2 // System.Xml.Schema.XmlSchemaSimpleType.cs
\r
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
\r
6 // Atsushi Enomoto ginga@kit.hi-ho.ne.jp
\r
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Xml.Serialization;
\r
32 using Mono.Xml.Schema;
\r
34 namespace System.Xml.Schema
\r
37 /// Summary description for XmlSchemaSimpleType.
\r
39 public class XmlSchemaSimpleType : XmlSchemaType
\r
41 const string xmlname = "simpleType";
\r
42 private static XmlSchemaSimpleType schemaLocationType;
\r
44 private XmlSchemaSimpleTypeContent content;
\r
46 internal bool islocal = true; // Assuming local means we have to specify islocal=false only in XmlSchema
\r
47 private bool recursed;
\r
48 private XmlSchemaDerivationMethod variety;
\r
51 // predefined simple types
\r
52 internal static readonly XmlSchemaSimpleType XsAnySimpleType;
\r
53 internal static readonly XmlSchemaSimpleType XsString;
\r
54 internal static readonly XmlSchemaSimpleType XsBoolean;
\r
55 internal static readonly XmlSchemaSimpleType XsDecimal;
\r
56 internal static readonly XmlSchemaSimpleType XsFloat;
\r
57 internal static readonly XmlSchemaSimpleType XsDouble;
\r
58 internal static readonly XmlSchemaSimpleType XsDuration;
\r
59 internal static readonly XmlSchemaSimpleType XsDateTime;
\r
60 internal static readonly XmlSchemaSimpleType XsTime;
\r
61 internal static readonly XmlSchemaSimpleType XsDate;
\r
62 internal static readonly XmlSchemaSimpleType XsGYearMonth;
\r
63 internal static readonly XmlSchemaSimpleType XsGYear;
\r
64 internal static readonly XmlSchemaSimpleType XsGMonthDay;
\r
65 internal static readonly XmlSchemaSimpleType XsGDay;
\r
66 internal static readonly XmlSchemaSimpleType XsGMonth;
\r
67 internal static readonly XmlSchemaSimpleType XsHexBinary;
\r
68 internal static readonly XmlSchemaSimpleType XsBase64Binary;
\r
69 internal static readonly XmlSchemaSimpleType XsAnyUri;
\r
70 internal static readonly XmlSchemaSimpleType XsQName;
\r
71 internal static readonly XmlSchemaSimpleType XsNotation;
\r
72 internal static readonly XmlSchemaSimpleType XsNormalizedString;
\r
73 internal static readonly XmlSchemaSimpleType XsToken;
\r
74 internal static readonly XmlSchemaSimpleType XsLanguage;
\r
75 internal static readonly XmlSchemaSimpleType XsNMToken;
\r
76 internal static readonly XmlSchemaSimpleType XsNMTokens;
\r
77 internal static readonly XmlSchemaSimpleType XsName;
\r
78 internal static readonly XmlSchemaSimpleType XsNCName;
\r
79 internal static readonly XmlSchemaSimpleType XsID;
\r
80 internal static readonly XmlSchemaSimpleType XsIDRef;
\r
81 internal static readonly XmlSchemaSimpleType XsIDRefs;
\r
82 internal static readonly XmlSchemaSimpleType XsEntity;
\r
83 internal static readonly XmlSchemaSimpleType XsEntities;
\r
84 internal static readonly XmlSchemaSimpleType XsInteger;
\r
85 internal static readonly XmlSchemaSimpleType XsNonPositiveInteger;
\r
86 internal static readonly XmlSchemaSimpleType XsNegativeInteger;
\r
87 internal static readonly XmlSchemaSimpleType XsLong;
\r
88 internal static readonly XmlSchemaSimpleType XsInt;
\r
89 internal static readonly XmlSchemaSimpleType XsShort;
\r
90 internal static readonly XmlSchemaSimpleType XsByte;
\r
91 internal static readonly XmlSchemaSimpleType XsNonNegativeInteger;
\r
92 internal static readonly XmlSchemaSimpleType XsUnsignedLong;
\r
93 internal static readonly XmlSchemaSimpleType XsUnsignedInt;
\r
94 internal static readonly XmlSchemaSimpleType XsUnsignedShort;
\r
95 internal static readonly XmlSchemaSimpleType XsUnsignedByte;
\r
96 internal static readonly XmlSchemaSimpleType XsPositiveInteger;
\r
98 internal static readonly XmlSchemaSimpleType XdtUntypedAtomic;
\r
99 internal static readonly XmlSchemaSimpleType XdtAnyAtomicType;
\r
100 internal static readonly XmlSchemaSimpleType XdtYearMonthDuration;
\r
101 internal static readonly XmlSchemaSimpleType XdtDayTimeDuration;
\r
104 static XmlSchemaSimpleType ()
\r
106 // This is not used in the meantime.
\r
107 XmlSchemaSimpleType st = new XmlSchemaSimpleType ();
\r
108 XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList ();
\r
109 list.ItemTypeName = new XmlQualifiedName ("anyURI", XmlSchema.Namespace);
\r
111 st.BaseXmlSchemaTypeInternal = null;
\r
112 st.variety = XmlSchemaDerivationMethod.List;
\r
113 schemaLocationType = st;
\r
116 // Built-In schema types
\r
117 XsAnySimpleType = BuildSchemaType ("anySimpleType", null);
\r
118 XsString = BuildSchemaType ("string", "anySimpleType");
\r
119 XsBoolean = BuildSchemaType ("boolean", "anySimpleType");
\r
120 XsDecimal = BuildSchemaType ("decimal", "anySimpleType");
\r
121 XsFloat = BuildSchemaType ("float", "anySimpleType");
\r
122 XsDouble = BuildSchemaType ("double", "anySimpleType");
\r
123 XsDuration = BuildSchemaType ("duration", "anySimpleType");
\r
124 XsDateTime = BuildSchemaType ("dateTime", "anySimpleType");
\r
125 XsTime = BuildSchemaType ("time", "anySimpleType");
\r
126 XsDate = BuildSchemaType ("date", "anySimpleType");
\r
127 XsGYearMonth = BuildSchemaType ("gYearMonth", "anySimpleType");
\r
128 XsGYear = BuildSchemaType ("gYear", "anySimpleType");
\r
129 XsGMonthDay = BuildSchemaType ("gMonthDay", "anySimpleType");
\r
130 XsGDay = BuildSchemaType ("gDay", "anySimpleType");
\r
131 XsGMonth = BuildSchemaType ("gMonth", "anySimpleType");
\r
132 XsHexBinary = BuildSchemaType ("hexBinary", "anySimpleType");
\r
133 XsBase64Binary = BuildSchemaType ("base64Binary", "anySimpleType");
\r
134 XsAnyUri = BuildSchemaType ("anyURI", "anySimpleType");
\r
135 XsQName = BuildSchemaType ("QName", "anySimpleType");
\r
136 XsNotation = BuildSchemaType ("NOTATION", "anySimpleType");
\r
138 XsNormalizedString = BuildSchemaType ("normalizedString", "string");
\r
139 XsToken = BuildSchemaType ("token", "normalizedString");
\r
140 XsLanguage = BuildSchemaType ("language", "token");
\r
141 XsNMToken = BuildSchemaType ("NMTOKEN", "token");
\r
142 XsName = BuildSchemaType ("Name", "token");
\r
143 XsNCName = BuildSchemaType ("NCName", "Name");
\r
145 XsID = BuildSchemaType ("ID", "NCName");
\r
146 XsIDRef = BuildSchemaType ("IDREF", "NCName");
\r
147 XsEntity = BuildSchemaType ("ENTITY", "NCName");
\r
149 XsInteger = BuildSchemaType ("integer", "decimal");
\r
150 XsNonPositiveInteger = BuildSchemaType ("nonPositiveInteger", "integer");
\r
151 XsNegativeInteger = BuildSchemaType ("negativeInteger", "nonPositiveInteger");
\r
152 XsLong = BuildSchemaType ("long", "integer");
\r
153 XsInt = BuildSchemaType ("int", "long");
\r
154 XsShort = BuildSchemaType ("short", "int");
\r
155 XsByte = BuildSchemaType ("byte", "short");
\r
156 XsNonNegativeInteger = BuildSchemaType ("nonNegativeInteger", "integer");
\r
157 XsUnsignedLong = BuildSchemaType ("unsignedLong", "nonNegativeInteger");
\r
158 XsUnsignedInt = BuildSchemaType ("unsignedInt", "unsignedLong");
\r
159 XsUnsignedShort = BuildSchemaType ("unsignedShort", "unsignedInt");
\r
160 XsUnsignedByte = BuildSchemaType ("unsignedByte", "unsignedShort");
\r
161 XsPositiveInteger = BuildSchemaType ("positiveInteger", "nonNegativeInteger");
\r
164 XdtAnyAtomicType = BuildSchemaType ("anyAtomicType", "anySimpleType", true, false);
\r
165 XdtUntypedAtomic = BuildSchemaType ("untypedAtomic", "anyAtomicType", true, true);
\r
166 XdtDayTimeDuration = BuildSchemaType ("dayTimeDuration", "duration", true, false);
\r
167 XdtYearMonthDuration = BuildSchemaType ("yearMonthDuration", "duration", true, false);
\r
169 // NMTOKENS, IDREFS, ENTITIES - lists
\r
170 XsIDRefs = new XmlSchemaSimpleType ();
\r
171 XmlSchemaSimpleTypeList sl = new XmlSchemaSimpleTypeList ();
\r
172 sl.ItemType = XsIDRef;
\r
173 XsIDRefs.Content = sl;
\r
174 XsEntities = new XmlSchemaSimpleType ();
\r
175 sl = new XmlSchemaSimpleTypeList ();
\r
176 sl.ItemType = XsEntity;
\r
177 XsEntities.Content = sl;
\r
178 XsNMTokens = new XmlSchemaSimpleType ();
\r
179 sl = new XmlSchemaSimpleTypeList ();
\r
180 sl.ItemType = XsNMToken;
\r
181 XsNMTokens.Content = sl;
\r
186 private static XmlSchemaSimpleType BuildSchemaType (string name, string baseName)
\r
188 return BuildSchemaType (name, baseName, false, false);
\r
191 private static XmlSchemaSimpleType BuildSchemaType (string name, string baseName, bool xdt, bool baseXdt)
\r
193 string ns = xdt ? "http://www.w3.org/2003/11/xpath-datatypes" : XmlSchema.Namespace;
\r
194 string ns2 = baseXdt ? "http://www.w3.org/2003/11/xpath-datatypes" : XmlSchema.Namespace;
\r
195 XmlSchemaSimpleType st = new XmlSchemaSimpleType ();
\r
196 st.QNameInternal = new XmlQualifiedName (name, ns);
\r
197 if (baseName != null)
\r
198 st.BaseXmlSchemaTypeInternal = XmlSchemaType. GetBuiltInSimpleType (new XmlQualifiedName (baseName, ns2));
\r
199 st.DatatypeInternal = XmlSchemaDatatype.FromName (st.QualifiedName);
\r
200 st.ValueConverter = XmlSchemaType.BuildConverter (st.TypeCode);
\r
205 internal static XsdAnySimpleType AnySimpleType {
\r
206 get { return XsdAnySimpleType.Instance; }
\r
209 internal static XmlSchemaSimpleType SchemaLocationType {
\r
210 get { return schemaLocationType; }
\r
213 public XmlSchemaSimpleType ()
\r
217 [XmlElement("restriction",typeof(XmlSchemaSimpleTypeRestriction),Namespace=XmlSchema.Namespace)]
\r
218 [XmlElement("list",typeof(XmlSchemaSimpleTypeList),Namespace=XmlSchema.Namespace)]
\r
219 [XmlElement("union",typeof(XmlSchemaSimpleTypeUnion),Namespace=XmlSchema.Namespace)]
\r
220 public XmlSchemaSimpleTypeContent Content
\r
222 get{ return content; }
\r
223 set{ content = value; }
\r
226 internal XmlSchemaDerivationMethod Variety
\r
228 get{ return variety; }
\r
232 /// For a simple Type:
\r
233 /// 1. Content must be present
\r
234 /// 2. id if present, must have be a valid ID
\r
235 /// a) If the simpletype is local
\r
236 /// 1- are from <xs:complexType name="simpleType"> and <xs:complexType name="localSimpleType">
\r
237 /// 1. name is prohibited
\r
238 /// 2. final is prohibited
\r
239 /// b) If the simpletype is toplevel
\r
240 /// 1- are from <xs:complexType name="simpleType"> and <xs:complexType name="topLevelSimpleType">
\r
241 /// 1. name is required, type must be NCName
\r
242 /// 2. Content is required
\r
243 /// 3. final can have values : #all | (list | union | restriction)
\r
244 /// 4. If final is set, finalResolved is same as final (but within the values of b.3)
\r
245 /// 5. If final is not set, the finalDefault of the schema (ie. only #all and restriction)
\r
246 /// 6. Base type is:
\r
247 /// 4.1 If restriction is chosen,the base type of restriction or elements
\r
248 /// 4.2 otherwise simple ur-type
\r
250 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
252 // If this is already compiled this time, simply skip.
\r
253 if (this.IsComplied (schema.CompilationId))
\r
256 if (Content != null)
\r
257 Content.Parent = this;
\r
262 if(this.islocal) // a
\r
264 if(this.Name != null) // a.1
\r
265 error(h,"Name is prohibited in a local simpletype");
\r
267 this.QNameInternal = new XmlQualifiedName(this.Name,schema.TargetNamespace);
\r
268 if(this.Final != XmlSchemaDerivationMethod.None) //a.2
\r
269 error(h,"Final is prohibited in a local simpletype");
\r
273 if(this.Name == null) //b.1
\r
274 error(h,"Name is required in top level simpletype");
\r
275 else if(!XmlSchemaUtil.CheckNCName(this.Name)) // b.1.2
\r
276 error(h,"name attribute of a simpleType must be NCName");
\r
278 this.QNameInternal = new XmlQualifiedName(this.Name,schema.TargetNamespace);
\r
280 //NOTE: Although the FinalResolved can be Empty, it is not a valid value for Final
\r
281 //DEVIATION: If an error occurs, the finaldefault is always consulted. This deviates
\r
282 // from the way MS implementation works.
\r
283 switch(this.Final) //b.3, b.4
\r
285 case XmlSchemaDerivationMethod.All:
\r
286 this.finalResolved = XmlSchemaDerivationMethod.All;
\r
288 case XmlSchemaDerivationMethod.List:
\r
289 case XmlSchemaDerivationMethod.Union:
\r
290 case XmlSchemaDerivationMethod.Restriction:
\r
291 this.finalResolved = Final;
\r
294 error(h,"The value of final attribute is not valid for simpleType");
\r
295 goto case XmlSchemaDerivationMethod.None;
\r
296 // use assignment from finaldefault on schema.
\r
297 case XmlSchemaDerivationMethod.None: // b.5
\r
298 XmlSchemaDerivationMethod flags =
\r
299 (XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.List |
\r
300 XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Union );
\r
301 switch (schema.FinalDefault) {
\r
302 case XmlSchemaDerivationMethod.All:
\r
303 finalResolved = XmlSchemaDerivationMethod.All;
\r
305 case XmlSchemaDerivationMethod.None:
\r
306 finalResolved = XmlSchemaDerivationMethod.Empty;
\r
309 finalResolved = schema.FinalDefault & flags;
\r
316 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
\r
318 if (Content != null)
\r
319 Content.OwnerType = this;
\r
321 if(this.Content == null) //a.3,b.2
\r
322 error(h,"Content is required in a simpletype");
\r
323 else if(Content is XmlSchemaSimpleTypeRestriction)
\r
325 this.resolvedDerivedBy = XmlSchemaDerivationMethod.Restriction;
\r
326 errorCount += ((XmlSchemaSimpleTypeRestriction)Content).Compile(h,schema);
\r
328 else if(Content is XmlSchemaSimpleTypeList)
\r
330 this.resolvedDerivedBy = XmlSchemaDerivationMethod.List;
\r
331 errorCount += ((XmlSchemaSimpleTypeList)Content).Compile(h,schema);
\r
333 else if(Content is XmlSchemaSimpleTypeUnion)
\r
335 this.resolvedDerivedBy = XmlSchemaDerivationMethod.Union;
\r
336 errorCount += ((XmlSchemaSimpleTypeUnion)Content).Compile(h,schema);
\r
339 this.CompilationId = schema.CompilationId;
\r
343 internal void CollectBaseType (ValidationEventHandler h, XmlSchema schema)
\r
345 if (Content is XmlSchemaSimpleTypeRestriction) {
\r
346 object o = ((XmlSchemaSimpleTypeRestriction) Content).GetActualType (h, schema, false);
\r
347 BaseXmlSchemaTypeInternal = o as XmlSchemaSimpleType;
\r
348 if (BaseXmlSchemaTypeInternal != null)
\r
349 DatatypeInternal = BaseXmlSchemaTypeInternal.Datatype;
\r
351 DatatypeInternal = o as XmlSchemaDatatype;
\r
353 // otherwise, actualBaseSchemaType is null
\r
355 DatatypeInternal = XmlSchemaSimpleType.AnySimpleType;
\r
358 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
360 // 3.14.6 Properties Correct.
\r
362 // 1. Post Compilation Properties
\r
363 // {name}, {target namespace} => QNameInternal. Already Compile()d.
\r
364 // {base type definition} => baseSchemaTypeInternal
\r
365 // {final} => finalResolved. Already Compile()d.
\r
366 // {variety} => resolvedDerivedBy. Already Compile()d.
\r
368 // 2. Should be checked by "recursed" field.
\r
370 if(IsValidated (schema.ValidationId))
\r
374 error (h, "Circular type reference was found.");
\r
379 CollectBaseType (h, schema);
\r
381 if (content != null)
\r
382 errorCount += content.Validate (h, schema);
\r
385 // BaseSchemaType property
\r
386 BaseXmlSchemaTypeInternal = content.ActualBaseSchemaType as XmlSchemaType;
\r
387 if (this.BaseXmlSchemaTypeInternal == null)
\r
388 this.DatatypeInternal = content.ActualBaseSchemaType as XmlSchemaDatatype;
\r
391 // Datatype property
\r
392 XmlSchemaSimpleType simple = BaseXmlSchemaType as XmlSchemaSimpleType;
\r
393 if (simple != null)
\r
394 this.DatatypeInternal = simple.Datatype;
\r
396 // DatatypeInternal = BaseSchemaType as XmlSchemaDatatype;
\r
399 XmlSchemaSimpleType baseSType = BaseXmlSchemaType as XmlSchemaSimpleType;
\r
400 if (baseSType != null) {
\r
401 if ((baseSType.FinalResolved & this.resolvedDerivedBy) != 0)
\r
402 error (h, "Specified derivation is prohibited by the base simple type.");
\r
406 if (this.resolvedDerivedBy == XmlSchemaDerivationMethod.Restriction &&
\r
408 this.variety = baseSType.Variety;
\r
410 this.variety = this.resolvedDerivedBy;
\r
412 // 3.14.6 Derivation Valid (Restriction, Simple)
\r
413 XmlSchemaSimpleTypeRestriction r = Content as XmlSchemaSimpleTypeRestriction;
\r
414 object baseType = BaseXmlSchemaType != null ? (object) BaseXmlSchemaType : Datatype;
\r
416 ValidateDerivationValid (baseType, r.Facets, h, schema);
\r
418 // TODO: describe which validation term this belongs to.
\r
419 XmlSchemaSimpleTypeList l = Content as XmlSchemaSimpleTypeList;
\r
421 XmlSchemaSimpleType itemSimpleType = l.ValidatedListItemType as XmlSchemaSimpleType;
\r
422 if (itemSimpleType != null && itemSimpleType.Content is XmlSchemaSimpleTypeList)
\r
423 error (h, "List type must not be derived from another list type.");
\r
427 ValidationId = schema.ValidationId;
\r
431 // 3.14.6 Derivation Valid (RestrictionSimple)
432 internal void ValidateDerivationValid (object baseType, XmlSchemaObjectCollection facets,
433 ValidationEventHandler h, XmlSchema schema)
436 XmlSchemaSimpleType baseSimpleType = baseType as XmlSchemaSimpleType;
437 switch (this.Variety) {
439 case XmlSchemaDerivationMethod.Restriction:
441 if (baseSimpleType != null && baseSimpleType.resolvedDerivedBy != XmlSchemaDerivationMethod.Restriction)
442 error (h, "Base schema type is not either atomic type or primitive type.");
444 if (baseSimpleType != null &&
445 (baseSimpleType.FinalResolved & XmlSchemaDerivationMethod.Restriction) != 0)
446 error (h, "Derivation by restriction is prohibited by the base simple type.");
447 // TODO: 1.3 facet restriction valid.
449 case XmlSchemaDerivationMethod.List:
451 XmlSchemaSimpleTypeList thisList = Content as XmlSchemaSimpleTypeList;
452 // 2.1 item list type not allowed
453 if (baseSimpleType != null && baseSimpleType.resolvedDerivedBy == XmlSchemaDerivationMethod.List)
454 error (h, "Base list schema type is not allowed.");
455 XmlSchemaSimpleTypeUnion baseUnion = baseSimpleType.Content as XmlSchemaSimpleTypeUnion;
456 if (baseUnion != null) {
457 bool errorFound = false;
458 foreach (object memberType in baseUnion.ValidatedTypes) {
459 XmlSchemaSimpleType memberST = memberType as XmlSchemaSimpleType;
460 if (memberST != null && memberST.resolvedDerivedBy == XmlSchemaDerivationMethod.List)
464 error (h, "Base union schema type should not contain list types.");
467 // 2.2 facets limited
469 foreach (XmlSchemaFacet facet in facets) {
470 if (facet is XmlSchemaLengthFacet ||
471 facet is XmlSchemaMaxLengthFacet ||
472 facet is XmlSchemaMinLengthFacet ||
473 facet is XmlSchemaEnumerationFacet ||
474 facet is XmlSchemaPatternFacet)
477 error (h, "Not allowed facet was found on this simple type which derives list type.");
480 case XmlSchemaDerivationMethod.Union:
485 foreach (XmlSchemaFacet facet in facets) {
486 if (facet is XmlSchemaEnumerationFacet ||
487 facet is XmlSchemaPatternFacet)
490 error (h, "Not allowed facet was found on this simple type which derives list type.");
496 // 3.14.6 Type Derivation OK (Simple)
497 internal bool ValidateTypeDerivationOK (object baseType,
498 ValidationEventHandler h, XmlSchema schema, bool raiseError)
501 // Note that anyType should also be allowed as anySimpleType.
502 if (this == baseType || baseType == XmlSchemaSimpleType.AnySimpleType ||
503 baseType == XmlSchemaComplexType.AnyType)
507 XmlSchemaSimpleType baseSimpleType = baseType as XmlSchemaSimpleType;
508 if (baseSimpleType != null &&
509 (baseSimpleType.FinalResolved & resolvedDerivedBy) != 0) {
511 error (h, "Specified derivation is prohibited by the base type.");
516 if (BaseXmlSchemaType == baseType || Datatype == baseType)
520 XmlSchemaSimpleType thisBaseSimpleType = BaseXmlSchemaType as XmlSchemaSimpleType;
521 if (thisBaseSimpleType != null) {
522 if (thisBaseSimpleType.ValidateTypeDerivationOK (baseType, h, schema, false))
528 case XmlSchemaDerivationMethod.Union:
529 case XmlSchemaDerivationMethod.List:
530 if (baseType == XmlSchemaSimpleType.AnySimpleType)
535 // 2.2.4 validly derived from one of the union member type.
536 if (baseSimpleType != null && baseSimpleType.Variety == XmlSchemaDerivationMethod.Union) {
537 foreach (object memberType in ((XmlSchemaSimpleTypeUnion) baseSimpleType.Content).ValidatedTypes)
538 if (this.ValidateTypeDerivationOK (memberType, h, schema, false))
543 error(h, "Invalid simple type derivation was found.");
547 internal string Normalize (string s, XmlNameTable nt, XmlNamespaceManager nsmgr)
549 return Content.Normalize (s, nt, nsmgr);
553 // final = (#all | (list | union | restriction))
\r
556 // {any attributes with non-schema namespace . . .}>
\r
557 // Content: (annotation?, (restriction | list | union))
\r
559 internal static XmlSchemaSimpleType Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
561 XmlSchemaSimpleType stype = new XmlSchemaSimpleType();
\r
562 reader.MoveToElement();
\r
564 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
566 error(h,"Should not happen :1: XmlSchemaGroup.Read, name="+reader.Name,null);
\r
571 stype.LineNumber = reader.LineNumber;
\r
572 stype.LinePosition = reader.LinePosition;
\r
573 stype.SourceUri = reader.BaseURI;
\r
575 while(reader.MoveToNextAttribute())
\r
577 if(reader.Name == "final")
\r
580 stype.Final = XmlSchemaUtil.ReadDerivationAttribute(reader, out innerex, "final",
\r
581 XmlSchemaUtil.FinalAllowed);
\r
582 if(innerex != null)
\r
583 error(h, "some invalid values not a valid value for final", innerex);
\r
585 else if(reader.Name == "id")
\r
587 stype.Id = reader.Value;
\r
589 else if(reader.Name == "name")
\r
591 stype.Name = reader.Value;
\r
593 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
595 error(h,reader.Name + " is not a valid attribute for simpleType",null);
\r
599 XmlSchemaUtil.ReadUnhandledAttribute(reader,stype);
\r
603 reader.MoveToElement();
\r
604 if(reader.IsEmptyElement)
\r
607 // Content: (annotation?, (restriction | list | union))
\r
609 while(reader.ReadNextElement())
\r
611 if(reader.NodeType == XmlNodeType.EndElement)
\r
613 if(reader.LocalName != xmlname)
\r
614 error(h,"Should not happen :2: XmlSchemaSimpleType.Read, name="+reader.Name,null);
\r
617 if(level <= 1 && reader.LocalName == "annotation")
\r
619 level = 2; //Only one annotation
\r
620 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
621 if(annotation != null)
\r
622 stype.Annotation = annotation;
\r
627 if(reader.LocalName == "restriction")
\r
630 XmlSchemaSimpleTypeRestriction restriction = XmlSchemaSimpleTypeRestriction.Read(reader,h);
\r
631 if(restriction != null)
\r
632 stype.content = restriction;
\r
635 if(reader.LocalName == "list")
\r
638 XmlSchemaSimpleTypeList list = XmlSchemaSimpleTypeList.Read(reader,h);
\r
640 stype.content = list;
\r
643 if(reader.LocalName == "union")
\r
646 XmlSchemaSimpleTypeUnion union = XmlSchemaSimpleTypeUnion.Read(reader,h);
\r
648 stype.content = union;
\r
652 reader.RaiseInvalidElementError();
\r