1212
1313import { existsSync , readFileSync } from 'fs' ;
1414import { resolve } from 'path' ;
15+ import { Constants } from '../Constants' ;
1516import { XMLUtils } from '../XMLUtils' ;
1617import { AttributeGroup } from '../schema/AttributeGroup' ;
1718import { BuiltinTypes } from '../schema/BuiltinTypes' ;
@@ -93,7 +94,7 @@ export class CompositeGrammar implements Grammar {
9394 const data : any = JSON . parse ( readFileSync ( grammarPath , 'utf8' ) ) ;
9495 const grammar : XMLSchemaGrammar = XMLSchemaGrammar . fromJSON ( data ) ;
9596
96- this . grammars . set ( 'http://www.w3.org/2001/XMLSchema' , grammar ) ;
97+ this . grammars . set ( Constants . XML_SCHEMA_NS , grammar ) ;
9798 }
9899 } catch ( error ) {
99100 // Silently continue - this is an optimization, not required
@@ -107,7 +108,7 @@ export class CompositeGrammar implements Grammar {
107108 const data : any = JSON . parse ( readFileSync ( grammarPath , 'utf8' ) ) ;
108109 const grammar : XMLSchemaGrammar = XMLSchemaGrammar . fromJSON ( data ) ;
109110
110- this . grammars . set ( 'http://www.w3.org/2001/XMLSchema-instance' , grammar ) ;
111+ this . grammars . set ( Constants . XML_SCHEMA_INSTANCE_NS , grammar ) ;
111112
112113 }
113114 } catch ( error ) {
@@ -137,14 +138,15 @@ export class CompositeGrammar implements Grammar {
137138 const resolvedNamespace : string = namespace ;
138139
139140 if ( prefix === '' ) {
140- const isSchemaDefault : boolean = resolvedNamespace === 'http://www.w3.org/2001/XMLSchema' ;
141+ const isSchemaDefault : boolean = resolvedNamespace === Constants . XML_SCHEMA_NS || resolvedNamespace === Constants . XML_SCHEMA_NS_SECURE ;
141142 if ( isSchemaDefault ) {
142143 // Avoid persisting the XML Schema default namespace as the
143144 // active default for instance documents.
144- if ( this . prefixToNamespace . get ( '' ) === 'http://www.w3.org/2001/XMLSchema' ) {
145+ const defaultPrefixNs = this . prefixToNamespace . get ( '' ) ;
146+ if ( defaultPrefixNs === Constants . XML_SCHEMA_NS || defaultPrefixNs === Constants . XML_SCHEMA_NS_SECURE ) {
145147 this . prefixToNamespace . delete ( '' ) ;
146148 }
147- if ( this . defaultNamespace === 'http://www.w3.org/2001/XMLSchema' ) {
149+ if ( this . defaultNamespace === Constants . XML_SCHEMA_NS || this . defaultNamespace === Constants . XML_SCHEMA_NS_SECURE ) {
148150 this . defaultNamespace = '' ;
149151 }
150152 return ;
@@ -640,7 +642,7 @@ export class CompositeGrammar implements Grammar {
640642 if ( ! elementDecl ) {
641643 const targetNamespace : string | undefined = grammar . getTargetNamespace ?.( ) ;
642644
643- if ( targetNamespace === 'http://www.w3.org/2001/XMLSchema' ) {
645+ if ( targetNamespace === Constants . XML_SCHEMA_NS || targetNamespace === Constants . XML_SCHEMA_NS_SECURE ) {
644646 // Allow schema documents to pass through structural validation.
645647 // Semantic validation is handled separately by XMLSchemaParser.
646648 return ValidationResult . success ( ) ;
@@ -1042,7 +1044,7 @@ export class CompositeGrammar implements Grammar {
10421044 const name : string | undefined = simpleType . getName ( ) ;
10431045 if ( name ) {
10441046 const localName : string = name . includes ( ':' ) ? name . substring ( name . indexOf ( ':' ) + 1 ) : name ;
1045- if ( namespace === 'http://www.w3.org/2001/XMLSchema' || name . startsWith ( 'xsd:' ) || name . startsWith ( 'xs:' ) ) {
1047+ if ( namespace === Constants . XML_SCHEMA_NS || namespace === Constants . XML_SCHEMA_NS_SECURE || name . startsWith ( 'xsd:' ) || name . startsWith ( 'xs:' ) ) {
10461048 return localName ;
10471049 }
10481050 }
0 commit comments