1111 *******************************************************************************/
1212
1313import { } from "../grammar/Grammar" ;
14+ import { XMLUtils } from "../XMLUtils" ;
1415import { SchemaType } from "./SchemaType" ;
1516import { XMLSchemaGrammar } from "./XMLSchemaGrammar" ;
16- import { XMLUtils } from "../XMLUtils" ;
1717
1818export class SchemaElementDecl {
1919 private name : string ;
@@ -27,6 +27,7 @@ export class SchemaElementDecl {
2727 private defaultValue ?: string ;
2828 private fixedValue ?: string ;
2929 private form : 'qualified' | 'unqualified' = 'unqualified' ;
30+ private namespaceURI ?: string ;
3031
3132 constructor ( name : string ) {
3233 this . validateName ( name ) ;
@@ -133,32 +134,40 @@ export class SchemaElementDecl {
133134 return this . fixedValue || this . defaultValue ;
134135 }
135136
137+ getNamespaceURI ( ) : string | undefined {
138+ return this . namespaceURI ;
139+ }
140+
141+ setNamespaceURI ( namespaceURI : string | undefined ) : void {
142+ this . namespaceURI = namespaceURI ;
143+ }
144+
136145 // Resolve type from grammar if type name is set but type object is not
137146 resolveType ( grammar : XMLSchemaGrammar ) : SchemaType | undefined {
138147 if ( this . type ) {
139148 return this . type ;
140149 }
141-
150+
142151 if ( this . typeName ) {
143152 return grammar . getTypeDefinition ( this . typeName ) ;
144153 }
145-
154+
146155 return undefined ;
147156 }
148157
149158 // Schema validation methods
150-
159+
151160 private validateName ( name : string ) : void {
152161 if ( ! name ) {
153162 throw new Error ( 'Element name cannot be empty' ) ;
154163 }
155-
164+
156165 // XML Schema spec: Element names must be valid NCNames (no spaces, no colons except for qualified names)
157166 // Check for invalid characters first (like spaces)
158167 if ( name . includes ( ' ' ) || name . includes ( '\t' ) || name . includes ( '\n' ) || name . includes ( '\r' ) ) {
159168 throw new Error ( `Element name '${ name } ' contains invalid whitespace characters - XML Schema element names must be valid NCNames` ) ;
160169 }
161-
170+
162171 // Skip validation for Clark notation (expanded QNames like {namespace}localName)
163172 if ( name . startsWith ( '{' ) ) {
164173 const closeBrace = name . indexOf ( '}' ) ;
@@ -171,14 +180,14 @@ export class SchemaElementDecl {
171180 return ;
172181 }
173182 }
174-
183+
175184 // Handle qualified names (prefix:localName) vs NCNames
176185 const colonIndex = name . indexOf ( ':' ) ;
177186 if ( colonIndex !== - 1 ) {
178187 // Qualified name - validate both prefix and local name as NCNames
179188 const prefix = name . substring ( 0 , colonIndex ) ;
180189 const localName = name . substring ( colonIndex + 1 ) ;
181-
190+
182191 if ( ! XMLUtils . isValidNCName ( prefix ) ) {
183192 throw new Error ( `Element name prefix '${ prefix } ' is not a valid NCName` ) ;
184193 }
@@ -214,12 +223,12 @@ export class SchemaElementDecl {
214223 this . validateName ( this . name ) ;
215224 this . validateOccurrence ( this . minOccurs , this . maxOccurs ) ;
216225 this . validateValueConstraints ( this . defaultValue , this . fixedValue ) ;
217-
226+
218227 // Schema spec: abstract elements cannot have default/fixed values
219228 if ( this . abstract && ( this . defaultValue !== undefined || this . fixedValue !== undefined ) ) {
220229 throw new Error ( 'Abstract elements cannot have default or fixed values' ) ;
221230 }
222-
231+
223232 // Schema spec: elements with type and inline type are mutually exclusive
224233 if ( this . type !== undefined && this . typeName !== undefined ) {
225234 throw new Error ( 'Element cannot have both inline type and type reference' ) ;
0 commit comments