2 // Mono.Xml.Schema.XsdValidatingReader.cs
5 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
7 // (C)2003 Atsushi Enomoto
11 // This class doesn't support set_XmlResolver, since it isn't common to XmlReader interface.
12 // Try to set that of xml reader which is used to construct this object.
15 using System.Collections;
16 using System.Collections.Specialized;
19 using System.Xml.Schema;
22 namespace Mono.Xml.Schema
24 public class XsdValidatingReader : XmlReader, IXmlLineInfo, IHasXmlSchemaInfo, IHasXmlParserContext
26 char [] wsChars = new char [] {' ', '\t', '\n', '\r'};
29 XmlValidatingReader xvReader;
30 IXmlLineInfo readerLineInfo;
31 bool laxElementValidation = true;
32 bool reportNoValidationError;
33 XmlSchemaCollection schemas = new XmlSchemaCollection ();
34 bool namespaces = true;
36 ArrayList idList = new ArrayList ();
37 ArrayList missingIDReferences = new ArrayList ();
40 ArrayList keyTables = new ArrayList ();
41 ArrayList currentKeyFieldConsumers = new ArrayList ();
43 XsdValidationStateManager stateManager = new XsdValidationStateManager ();
44 XsdValidationContext context = new XsdValidationContext ();
45 XsdValidationState childParticleState;
48 StringBuilder storedCharacters = new StringBuilder ();
49 bool shouldValidateCharacters;
50 int skipValidationDepth = -1;
52 XmlSchemaAttribute [] defaultAttributes = new XmlSchemaAttribute [0];
53 int currentDefaultAttribute = -1;
54 XmlQualifiedName currentQName;
56 ArrayList elementQNameStack = new ArrayList ();
60 int nonDefaultAttributeCount;
61 bool defaultAttributeConsumed;
63 // Validation engine cached object
64 ArrayList defaultAttributesCache = new ArrayList ();
65 ArrayList tmpKeyrefPool = new ArrayList ();
68 public XsdValidatingReader (XmlReader reader)
73 public XsdValidatingReader (XmlReader reader, XmlReader validatingReader)
76 xvReader = validatingReader as XmlValidatingReader;
77 if (xvReader != null) {
78 if (xvReader.ValidationType == ValidationType.None)
79 reportNoValidationError = true;
81 readerLineInfo = reader as IXmlLineInfo;
85 private XmlQualifiedName CurrentQName {
87 if (currentQName == null)
88 currentQName = new XmlQualifiedName (LocalName, NamespaceURI);
93 internal ArrayList CurrentKeyFieldConsumers {
94 get { return currentKeyFieldConsumers; }
97 // Public Non-overrides
99 public bool Namespaces {
100 get { return namespaces; }
101 set { namespaces = value; }
104 public XmlReader Reader {
105 get { return reader; }
108 // This should be changed before the first Read() call.
109 public XmlSchemaCollection Schemas {
110 get { return schemas; }
113 public object SchemaType {
115 if (ReadState != ReadState.Interactive)
119 case XmlNodeType.Element:
120 if (context.ActualType != null)
121 return context.ActualType;
122 else if (context.Element != null)
123 return context.Element.ElementType;
126 case XmlNodeType.Attribute:
127 // TODO: Default attribute support
128 XmlSchemaComplexType ct = context.ActualType as XmlSchemaComplexType;
130 XmlSchemaAttribute attdef = ct.AttributeUses [CurrentQName] as XmlSchemaAttribute;
132 return attdef.AttributeType;
141 // This property is never used in Mono.
142 public ValidationType ValidationType {
144 if (reportNoValidationError)
145 return ValidationType.None;
147 return ValidationType.Schema;
151 // It is used only for independent XmlReader use, not for XmlValidatingReader.
152 public object ReadTypedValue ()
154 XmlSchemaDatatype dt = SchemaType as XmlSchemaDatatype;
155 XmlSchemaSimpleType st = SchemaType as XmlSchemaSimpleType;
162 case XmlNodeType.Element:
166 storedCharacters.Length = 0;
171 case XmlNodeType.SignificantWhitespace:
172 case XmlNodeType.Text:
173 case XmlNodeType.CDATA:
174 storedCharacters.Append (Value);
176 case XmlNodeType.Comment:
182 } while (loop && !EOF);
183 return dt.ParseValue (storedCharacters.ToString (), NameTable, ParserContext.NamespaceManager);
184 case XmlNodeType.Attribute:
185 return dt.ParseValue (Value, NameTable, ParserContext.NamespaceManager);
190 public ValidationEventHandler ValidationEventHandler;
192 // Public Overrided Properties
194 public override int AttributeCount {
197 if (NodeType == XmlNodeType.Element)
198 return attributeCount;
202 return reader.AttributeCount;
204 return nonDefaultAttributeCount + defaultAttributes.Length;
208 public override string BaseURI {
209 get { return reader.BaseURI; }
212 // If this class is used to implement XmlValidatingReader,
213 // it should be left to DTDValidatingReader. In other cases,
214 // it depends on the reader's ability.
215 public override bool CanResolveEntity {
216 get { return reader.CanResolveEntity; }
219 public override int Depth {
221 if (currentDefaultAttribute < 0)
223 if (this.defaultAttributeConsumed)
224 return reader.Depth + 2;
225 return reader.Depth + 1;
229 public override bool EOF {
230 get { return reader.EOF; }
233 public override bool HasValue {
235 if (currentDefaultAttribute < 0)
236 return reader.HasValue;
241 public override bool IsDefault {
243 if (currentDefaultAttribute < 0)
244 return reader.IsDefault;
249 public override bool IsEmptyElement {
251 if (currentDefaultAttribute < 0)
252 return reader.IsEmptyElement;
257 public override string this [int i] {
258 get { return GetAttribute (i); }
261 public override string this [string name] {
262 get { return GetAttribute (name); }
265 public override string this [string localName, string ns] {
266 get { return GetAttribute (localName, ns); }
269 int IXmlLineInfo.LineNumber {
270 get { return readerLineInfo != null ? readerLineInfo.LineNumber : 0; }
273 int IXmlLineInfo.LinePosition {
274 get { return readerLineInfo != null ? readerLineInfo.LinePosition : 0; }
277 public override string LocalName {
279 if (currentDefaultAttribute < 0)
280 return reader.LocalName;
281 if (defaultAttributeConsumed)
283 return defaultAttributes [currentDefaultAttribute].QualifiedName.Name;
287 public override string Name {
289 if (currentDefaultAttribute < 0)
291 if (defaultAttributeConsumed)
294 XmlQualifiedName qname = defaultAttributes [currentDefaultAttribute].QualifiedName;
295 string prefix = Prefix;
296 if (prefix == String.Empty)
299 return String.Concat (prefix, ":", qname.Name);
303 public override string NamespaceURI {
305 if (currentDefaultAttribute < 0)
306 return reader.NamespaceURI;
307 if (defaultAttributeConsumed)
309 return defaultAttributes [currentDefaultAttribute].QualifiedName.Namespace;
313 public override XmlNameTable NameTable {
314 get { return reader.NameTable; }
317 public override XmlNodeType NodeType {
319 if (currentDefaultAttribute < 0)
320 return reader.NodeType;
321 if (defaultAttributeConsumed)
322 return XmlNodeType.Text;
323 return XmlNodeType.Attribute;
327 public XmlParserContext ParserContext {
328 get { return XmlSchemaUtil.GetParserContext (reader); }
331 public override string Prefix {
333 if (currentDefaultAttribute < 0)
334 return reader.Prefix;
335 if (defaultAttributeConsumed)
337 XmlQualifiedName qname = defaultAttributes [currentDefaultAttribute].QualifiedName;
338 string prefix = this.ParserContext.NamespaceManager.LookupPrefix (qname.Namespace);
346 public override char QuoteChar {
347 get { return reader.QuoteChar; }
350 public override ReadState ReadState {
351 get { return reader.ReadState; }
354 public override string Value {
356 if (currentDefaultAttribute < 0)
358 return defaultAttributes [currentDefaultAttribute].ValidatedDefaultValue;
362 XmlQualifiedName qnameXmlLang = new XmlQualifiedName ("lang", XmlNamespaceManager.XmlnsXml);
364 public override string XmlLang {
366 string xmlLang = reader.XmlLang;
369 int idx = this.FindDefaultAttribute ("lang", XmlNamespaceManager.XmlnsXml);
372 return defaultAttributes [idx].ValidatedDefaultValue;
376 public override XmlSpace XmlSpace {
378 XmlSpace space = reader.XmlSpace;
379 if (space != XmlSpace.None)
381 int idx = this.FindDefaultAttribute ("space", XmlNamespaceManager.XmlnsXml);
383 return XmlSpace.None;
384 return (XmlSpace) Enum.Parse (typeof (XmlSpace), defaultAttributes [idx].ValidatedDefaultValue, false);
390 private XmlQualifiedName QualifyName (string name)
392 int colonAt = name.IndexOf (':');
394 return new XmlQualifiedName (name, null);
396 return new XmlQualifiedName (name.Substring (colonAt + 1),
397 LookupNamespace (name.Substring (0, colonAt)));
400 private void HandleError (string error)
402 HandleError (error, null);
405 private void HandleError (string error, Exception innerException)
407 if (reportNoValidationError) // extra quick check
410 XmlSchemaException schemaException = new XmlSchemaException (error,
411 this, this.BaseURI, null, innerException);
412 HandleError (schemaException);
415 private void HandleError (XmlSchemaException schemaException)
417 if (reportNoValidationError)
420 ValidationEventArgs e = new ValidationEventArgs (schemaException,
421 schemaException.Message, XmlSeverityType.Error);
423 if (this.ValidationEventHandler != null)
424 this.ValidationEventHandler (this, e);
425 else if (xvReader != null)
426 xvReader.OnValidationEvent (this, e);
429 this.xvReader.OnValidationEvent (this, e);
435 private XmlSchemaElement FindElement (string name, string ns)
437 foreach (XmlSchema target in schemas) {
438 XmlSchema matches = target.Schemas [reader.NamespaceURI];
439 if (matches != null) {
440 XmlSchemaElement result = target.Elements [new XmlQualifiedName (reader.LocalName, reader.NamespaceURI)] as XmlSchemaElement;
448 private XmlSchemaType FindType (XmlQualifiedName qname)
450 foreach (XmlSchema target in schemas) {
451 XmlSchemaType type = target.SchemaTypes [qname] as XmlSchemaType;
458 private void ValidateStartElementParticle ()
460 stateManager.CurrentElement = null;
461 context.ParticleState = context.ParticleState.EvaluateStartElement (reader.LocalName, reader.NamespaceURI);
462 if (context.ParticleState == XsdValidationState.Invalid)
463 HandleError ("Invalid start element: " + reader.NamespaceURI + ":" + reader.LocalName);
465 context.Element = stateManager.CurrentElement;
466 if (context.Element != null)
467 context.SchemaType = context.Element.ElementType;
470 private void ValidateEndElementParticle ()
472 if (childParticleState != null) {
473 if (!childParticleState.EvaluateEndElement ()) {
474 HandleError ("Invalid end element: " + reader.Name);
477 context.PopScope (reader.Depth);
480 // Utility for missing validation completion related to child items.
481 private void ValidateCharacters ()
483 // TODO: value context validation here.
484 if (xsiNilDepth >= 0 && xsiNilDepth < reader.Depth)
485 HandleError ("Element item appeared, while current element context is nil.");
487 storedCharacters.Append (reader.Value);
490 // Utility for missing validation completion related to child items.
491 private void ValidateEndCharacters ()
493 if (context.ActualType == null)
496 string value = storedCharacters.ToString ();
498 if (storedCharacters.Length == 0) {
499 // 3.3.4 Element Locally Valid (Element) 5.1.2
500 // TODO: check entire DefaultValid (3.3.6)
501 if (context.Element != null && context.Element.ValidatedDefaultValue != null)
502 value = context.Element.ValidatedDefaultValue;
505 XmlSchemaDatatype dt = context.ActualType as XmlSchemaDatatype;
506 XmlSchemaSimpleType st = context.ActualType as XmlSchemaSimpleType;
509 // if (st.Variety == XmlSchemaDerivationMethod.Restriction)
512 XmlSchemaComplexType ct = context.ActualType as XmlSchemaComplexType;
514 switch (ct.ContentType) {
515 case XmlSchemaContentType.ElementOnly:
516 case XmlSchemaContentType.Empty:
517 if (storedCharacters.Length > 0)
518 HandleError ("Character content not allowed.");
524 // 3.3.4 Element Locally Valid (Element) :: 5.2.2.2. Fixed value constraints
525 if (context.Element != null && context.Element.ValidatedFixedValue != null)
526 if (value != context.Element.ValidatedFixedValue)
527 HandleError ("Fixed value constraint was not satisfied.");
528 AssessStringValid (st, dt, value);
531 // Identity field value
532 while (this.currentKeyFieldConsumers.Count > 0) {
533 XsdKeyEntryField field = this.currentKeyFieldConsumers [0] as XsdKeyEntryField;
534 if (field.Identity != null)
535 HandleError ("Two or more identical field was found. Former value is '" + field.Identity + "' .");
536 object identity = null;
539 identity = dt.ParseValue (value, NameTable, ParserContext.NamespaceManager);
540 } catch (Exception ex) { // FIXME: (wishlist) This is bad manner ;-(
541 HandleError ("Identity value is invalid against its data type " + dt.TokenizedType, ex);
544 if (identity == null)
547 if (!field.SetIdentityField (identity, dt as XsdAnySimpleType, this))
548 HandleError ("Two or more identical key value was found: '" + value + "' .");
549 this.currentKeyFieldConsumers.RemoveAt (0);
552 shouldValidateCharacters = false;
555 // 3.14.4 String Valid
556 private void AssessStringValid (XmlSchemaSimpleType st,
557 XmlSchemaDatatype dt, string value)
559 XmlSchemaDatatype validatedDatatype = dt;
561 string normalized = validatedDatatype.Normalize (value);
563 XmlSchemaDatatype itemDatatype;
564 XmlSchemaSimpleType itemSimpleType;
565 switch (st.DerivedBy) {
566 case XmlSchemaDerivationMethod.List:
567 XmlSchemaSimpleTypeList listContent = st.Content as XmlSchemaSimpleTypeList;
568 values = normalized.Split (wsChars);
569 itemDatatype = listContent.ValidatedListItemType as XmlSchemaDatatype;
570 itemSimpleType = listContent.ValidatedListItemType as XmlSchemaSimpleType;
571 foreach (string each in values) {
572 if (each == String.Empty)
574 // validate against ValidatedItemType
575 if (itemDatatype != null) {
577 itemDatatype.ParseValue (each, NameTable, ParserContext.NamespaceManager);
578 } catch (Exception ex) { // FIXME: (wishlist) better exception handling ;-(
579 HandleError ("List type value contains one or more invalid values.", ex);
584 AssessStringValid (itemSimpleType, itemSimpleType.Datatype, each);
587 case XmlSchemaDerivationMethod.Union:
588 XmlSchemaSimpleTypeUnion union = st.Content as XmlSchemaSimpleTypeUnion;
590 string each = normalized;
591 // validate against ValidatedItemType
593 foreach (object eachType in union.ValidatedTypes) {
594 itemDatatype = eachType as XmlSchemaDatatype;
595 itemSimpleType = eachType as XmlSchemaSimpleType;
596 if (itemDatatype != null) {
598 itemDatatype.ParseValue (each, NameTable, ParserContext.NamespaceManager);
599 } catch (Exception) { // FIXME: (wishlist) better exception handling ;-(
605 AssessStringValid (itemSimpleType, itemSimpleType.Datatype, each);
606 } catch (XmlSchemaException) {
614 HandleError ("Union type value contains one or more invalid values.");
619 case XmlSchemaDerivationMethod.Restriction:
620 XmlSchemaSimpleTypeRestriction str = st.Content as XmlSchemaSimpleTypeRestriction;
623 if (!str.ValidateValueWithFacets (normalized, NameTable)) {
624 HandleError ("Specified value was invalid against the facets.");
628 validatedDatatype = st.Datatype;
632 if (validatedDatatype != null) {
634 validatedDatatype.ParseValue (value, NameTable, ParserContext.NamespaceManager);
635 } catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-(
636 HandleError ("Invalidly typed data was specified.", ex);
641 private object GetLocalTypeDefinition (string name)
643 object xsiType = null;
644 XmlQualifiedName typeQName = QualifyName (name);
645 if (typeQName.Namespace == XmlSchema.Namespace) {
646 if (typeQName.Name == "anyType")
647 xsiType = XmlSchemaComplexType.AnyType;
649 xsiType = XmlSchemaDatatype.FromName (typeQName);
652 xsiType = FindType (typeQName);
656 // It is common to ElementLocallyValid::4 and SchemaValidityAssessment::1.2.1.2.4
657 private void AssessLocalTypeDerivationOK (object xsiType, object baseType, XmlSchemaDerivationMethod flag)
659 XmlSchemaType xsiSchemaType = xsiType as XmlSchemaType;
660 XmlSchemaComplexType baseComplexType = baseType as XmlSchemaComplexType;
661 XmlSchemaComplexType xsiComplexType = xsiSchemaType as XmlSchemaComplexType;
662 if (xsiType != baseType) {
663 // Extracted (not extraneous) check for 3.4.6 TypeDerivationOK.
664 if (baseComplexType != null)
665 flag |= baseComplexType.BlockResolved;
666 if (flag == XmlSchemaDerivationMethod.All) {
667 HandleError ("Prohibited element type substitution.");
669 } else if (xsiSchemaType != null && (flag & xsiSchemaType.DerivedBy) != 0) {
670 HandleError ("Prohibited element type substitution.");
675 if (xsiComplexType != null)
677 xsiComplexType.ValidateTypeDerivationOK (baseType, null, null);
678 } catch (XmlSchemaException ex) {
679 // HandleError ("Locally specified schema complex type derivation failed. " + ex.Message, ex);
683 XmlSchemaSimpleType xsiSimpleType = xsiType as XmlSchemaSimpleType;
684 if (xsiSimpleType != null) {
686 xsiSimpleType.ValidateTypeDerivationOK (baseType, null, null, true);
687 } catch (XmlSchemaException ex) {
688 // HandleError ("Locally specified schema simple type derivation failed. " + ex.Message, ex);
692 else if (xsiType is XmlSchemaDatatype) {
696 HandleError ("Primitive data type cannot be derived type using xsi:type specification.");
700 // Section 3.3.4 of the spec.
701 private void AssessStartElementSchemaValidity ()
703 // If the reader is inside xsi:nil (and failed on validation),
704 // then simply skip its content.
705 if (xsiNilDepth >= 0 && xsiNilDepth < reader.Depth)
706 HandleError ("Element item appeared, while current element context is nil.");
708 context.Load (reader.Depth);
709 if (childParticleState != null) {
710 context.ParticleState = childParticleState;
711 childParticleState = null;
714 // If validation state exists, then first assess particle validity.
715 if (context.ParticleState != null) {
716 ValidateStartElementParticle ();
719 string xsiNilValue = GetAttribute ("nil", XmlSchema.InstanceNamespace);
720 if (xsiNilValue != null)
721 xsiNilValue = xsiNilValue.Trim (XmlChar.WhitespaceChars);
722 bool isXsiNil = xsiNilValue == "true";
723 if (isXsiNil && this.xsiNilDepth < 0)
724 xsiNilDepth = reader.Depth;
726 // [Schema Validity Assessment (Element) 1.2]
727 // Evaluate "local type definition" from xsi:type.
728 // (See spec 3.3.4 Schema Validity Assessment (Element) 1.2.1.2.3.
729 // Note that Schema Validity Assessment(Element) 1.2 takes
730 // precedence than 1.1 of that.
732 string xsiTypeName = reader.GetAttribute ("type", XmlSchema.InstanceNamespace);
733 if (xsiTypeName != null) {
734 xsiTypeName = xsiTypeName.Trim (XmlChar.WhitespaceChars);
735 object xsiType = GetLocalTypeDefinition (xsiTypeName);
737 HandleError ("The instance type was not found: " + xsiTypeName + " .");
739 XmlSchemaType xsiSchemaType = xsiType as XmlSchemaType;
740 if (xsiSchemaType != null && this.context.Element != null) {
741 XmlSchemaType elemBaseType = context.Element.ElementType as XmlSchemaType;
742 if (elemBaseType != null && (xsiSchemaType.DerivedBy & elemBaseType.FinalResolved) != 0)
743 HandleError ("The instance type is prohibited by the type of the context element.");
744 if (elemBaseType != xsiType && (xsiSchemaType.DerivedBy & this.context.Element.BlockResolved) != 0)
745 HandleError ("The instance type is prohibited by the context element.");
747 XmlSchemaComplexType xsiComplexType = xsiType as XmlSchemaComplexType;
748 if (xsiComplexType != null && xsiComplexType.IsAbstract)
749 HandleError ("The instance type is abstract: " + xsiTypeName + " .");
751 // If current schema type exists, then this xsi:type must be
752 // valid extension of that type. See 1.2.1.2.4.
753 if (context.Element != null) {
754 // FIXME: supply *correct* base type
755 AssessLocalTypeDerivationOK (xsiType, context.Element.ElementType, context.Element.BlockResolved);
757 AssessStartElementLocallyValidType (xsiType); // 1.2.2:
758 context.LocalTypeDefinition = xsiType;
763 // Create Validation Root, if not exist.
764 // [Schema Validity Assessment (Element) 1.1]
765 if (context.Element == null)
766 context.Element = FindElement (reader.LocalName, reader.NamespaceURI);
767 if (context.Element != null) {
768 if (xsiTypeName == null) {
769 context.SchemaType = context.Element.ElementType;
770 AssessElementLocallyValidElement (context.Element, xsiNilValue); // 1.1.2
774 switch (stateManager.ProcessContents) {
775 case XmlSchemaContentProcessing.Skip:
777 case XmlSchemaContentProcessing.Lax:
779 schema = schemas [reader.NamespaceURI];
780 if (schema != null && !schema.missedSubComponents)
781 HandleError ("Element declaration for " + reader.LocalName + " is missing.");
785 schema = schemas [reader.NamespaceURI];
786 if (xsiTypeName == null && (schema == null || !schema.missedSubComponents))
787 HandleError ("Element declaration for " + reader.LocalName + " is missing.");
792 if (stateManager.ProcessContents == XmlSchemaContentProcessing.Skip)
793 skipValidationDepth = reader.Depth;
795 // Finally, create child particle state.
796 XmlSchemaComplexType xsComplexType = SchemaType as XmlSchemaComplexType;
797 if (xsComplexType != null)
798 childParticleState = stateManager.Create (xsComplexType.ContentTypeParticle);
799 else if (stateManager.ProcessContents == XmlSchemaContentProcessing.Lax)
800 childParticleState = stateManager.Create (XmlSchemaAny.AnyTypeContent);
802 childParticleState = stateManager.Create (XmlSchemaParticle.Empty);
804 AssessStartIdentityConstraints ();
806 context.PushScope (reader.Depth);
809 // 3.3.4 Element Locally Valid (Element)
810 private void AssessElementLocallyValidElement (XmlSchemaElement element, string xsiNilValue)
812 XmlQualifiedName qname = new XmlQualifiedName (reader.LocalName, reader.NamespaceURI);
815 HandleError ("Element declaration is required for " + qname);
817 if (element.actualIsAbstract)
818 HandleError ("Abstract element declaration was specified for " + qname);
820 if (!element.actualIsNillable && xsiNilValue != null)
821 HandleError ("This element declaration is not nillable: " + qname);
823 // Note that 3.2.1 xsi:nil constraints are to be validated in
824 else if (xsiNilValue == "true") {
825 // AssessElementSchemaValidity() and ValidateCharacters()
827 if (element.ValidatedFixedValue != null)
828 HandleError ("Schema instance nil was specified, where the element declaration for " + qname + "has fixed value constraints.");
831 string xsiType = reader.GetAttribute ("type", XmlSchema.InstanceNamespace);
832 if (xsiType != null) {
833 context.LocalTypeDefinition = GetLocalTypeDefinition (xsiType);
834 AssessLocalTypeDerivationOK (context.LocalTypeDefinition, element.ElementType, element.BlockResolved);
837 // 5 Not all things cannot be assessed here.
838 // It is common to 5.1 and 5.2
839 if (element.ElementType != null)
840 AssessStartElementLocallyValidType (SchemaType);
842 // 6. should be out from here.
843 // See invokation of AssessStartIdentityConstraints().
845 // 7 is going to be validated in Read() (in case of xmlreader's EOF).
848 // 3.3.4 Element Locally Valid (Type)
849 private void AssessStartElementLocallyValidType (object schemaType)
851 if (schemaType == null) { // 1.
852 HandleError ("Schema type does not exist.");
855 XmlSchemaComplexType cType = schemaType as XmlSchemaComplexType;
856 XmlSchemaSimpleType sType = schemaType as XmlSchemaSimpleType;
859 while (reader.MoveToNextAttribute ()) {
860 if (reader.NamespaceURI == XmlNamespaceManager.XmlnsXmlns)
862 if (reader.NamespaceURI != XmlSchema.InstanceNamespace)
863 HandleError ("Current simple type cannot accept attributes other than schema instance namespace.");
864 switch (reader.LocalName) {
867 case "schemaLocation":
868 case "noNamespaceSchemaLocation":
871 HandleError ("Unknown schema instance namespace attribute: " + reader.LocalName);
875 reader.MoveToElement ();
876 // 3.1.2 and 3.1.3 cannot be assessed here.
877 } else if (cType != null) {
878 if (cType.IsAbstract) { // 2.
879 HandleError ("Target complex type is abstract.");
883 AssessElementLocallyValidComplexType (cType);
887 // 3.4.4 Element Locally Valid (Complex Type)
888 // TODO ("wild IDs constraints.")
889 private void AssessElementLocallyValidComplexType (XmlSchemaComplexType cType)
892 if (cType.IsAbstract)
893 HandleError ("Target complex type is abstract.");
895 // 2 (xsi:nil and content prohibition)
896 // See AssessStartElementSchemaValidity() and ValidateCharacters()
898 string elementNs = reader.NamespaceURI;
899 // 3. attribute uses and
901 while (reader.MoveToNextAttribute ()) {
902 if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/")
904 else if (reader.NamespaceURI == XmlSchema.InstanceNamespace)
906 XmlQualifiedName qname = new XmlQualifiedName (reader.LocalName, reader.NamespaceURI);
907 object attMatch = FindAttributeDeclaration (cType, qname, elementNs);
908 if (attMatch == null)
909 HandleError ("Attribute declaration was not found for " + qname);
911 XmlSchemaAttribute attdecl = attMatch as XmlSchemaAttribute;
912 if (attdecl == null) { // i.e. anyAttribute
913 XmlSchemaAnyAttribute anyAttrMatch = attMatch as XmlSchemaAnyAttribute;
915 AssessAttributeLocallyValidUse (attdecl);
916 AssessAttributeLocallyValid (attdecl, true);
920 reader.MoveToElement ();
922 // Collect default attributes.
924 // FIXME: FixedValue check maybe extraneous.
925 foreach (XmlSchemaAttribute attr in cType.AttributeUses) {
926 if (reader [attr.QualifiedName.Name, attr.QualifiedName.Namespace] == null) {
927 if (attr.ValidatedUse == XmlSchemaUse.Required &&
928 attr.ValidatedFixedValue == null)
929 HandleError ("Required attribute " + attr.QualifiedName + " was not found.");
930 else if (attr.ValidatedDefaultValue != null)
931 defaultAttributesCache.Add (attr);
934 defaultAttributes = (XmlSchemaAttribute [])
935 defaultAttributesCache.ToArray (typeof (XmlSchemaAttribute));
936 context.DefaultAttributes = defaultAttributes;
937 defaultAttributesCache.Clear ();
938 // 5. wild IDs was already checked above.
941 // Spec 3.10.4 Item Valid (Wildcard)
942 private bool AttributeWildcardItemValid (XmlSchemaAnyAttribute anyAttr, XmlQualifiedName qname)
944 if (anyAttr.HasValueAny)
946 if (anyAttr.HasValueOther && (anyAttr.TargetNamespace == "" || reader.NamespaceURI != anyAttr.TargetNamespace))
948 if (anyAttr.HasValueTargetNamespace && reader.NamespaceURI == anyAttr.TargetNamespace)
950 if (anyAttr.HasValueLocal && reader.NamespaceURI == "")
952 foreach (string ns in anyAttr.ResolvedNamespaces)
953 if (ns == reader.NamespaceURI)
958 private XmlSchemaObject FindAttributeDeclaration (XmlSchemaComplexType cType,
959 XmlQualifiedName qname, string elementNs)
961 XmlSchemaObject result = cType.AttributeUses [qname];
964 if (cType.AttributeWildcard == null)
967 if (!AttributeWildcardItemValid (cType.AttributeWildcard, qname))
970 if (cType.AttributeWildcard.ProcessContents == XmlSchemaContentProcessing.Skip)
971 return cType.AttributeWildcard;
972 foreach (XmlSchema schema in schemas) {
973 foreach (XmlSchemaAttribute attr in schema.Attributes)
974 if (attr.QualifiedName == qname)
977 if (cType.AttributeWildcard.ProcessContents == XmlSchemaContentProcessing.Lax)
978 return cType.AttributeWildcard;
983 // 3.2.4 Attribute Locally Valid and 3.4.4 - 5.wildIDs
985 private void AssessAttributeLocallyValid (XmlSchemaAttribute attr, bool checkWildIDs)
988 switch (reader.NamespaceURI) {
989 case XmlNamespaceManager.XmlnsXml:
990 case XmlNamespaceManager.XmlnsXmlns:
991 case XmlSchema.InstanceNamespace:
995 if (attr.AttributeType == null)
996 HandleError ("Attribute type is missing for " + attr.QualifiedName);
997 XmlSchemaDatatype dt = attr.AttributeType as XmlSchemaDatatype;
999 dt = ((XmlSchemaSimpleType) attr.AttributeType).Datatype;
1000 // It is a bit heavy process, so let's omit as long as possible ;-)
1001 if (dt != XmlSchemaSimpleType.AnySimpleType || attr.ValidatedFixedValue != null) {
1002 string normalized = dt.Normalize (reader.Value);
1003 object parsedValue = null;
1005 dt.ParseValue (normalized, reader.NameTable, this.ParserContext.NamespaceManager);
1006 } catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-(
1007 HandleError ("Attribute value is invalid against its data type " + dt.TokenizedType, ex);
1009 if (attr.ValidatedFixedValue != null && attr.ValidatedFixedValue != normalized)
1010 HandleError ("The value of the attribute " + attr.QualifiedName + " does not match with its fixed value.");
1011 // FIXME: this is extraneous checks in 3.2.4 Attribute Locally Valid.
1013 AssessEachAttributeIdentityConstraint (dt, normalized, parsedValue);
1017 private void AssessEachAttributeIdentityConstraint (XmlSchemaDatatype dt,
1018 string normalized, object parsedValue)
1020 // Get normalized value and (if required) parsedValue if missing.
1021 switch (dt.TokenizedType) {
1022 case XmlTokenizedType.IDREFS:
1023 if (normalized == null)
1024 normalized = dt.Normalize (reader.Value);
1025 if (parsedValue == null)
1026 parsedValue = dt.ParseValue (normalized, reader.NameTable, ParserContext.NamespaceManager);
1028 case XmlTokenizedType.ID:
1029 case XmlTokenizedType.IDREF:
1030 if (normalized == null)
1031 normalized = dt.Normalize (reader.Value);
1035 // Validate identity constraints.
1036 switch (dt.TokenizedType) {
1037 case XmlTokenizedType.ID:
1038 if (thisElementId != null)
1039 HandleError ("ID type attribute was already assigned in the containing element.");
1040 thisElementId = normalized;
1041 idList.Add (normalized);
1043 case XmlTokenizedType.IDREF:
1044 if (missingIDReferences.Contains (normalized))
1045 missingIDReferences.Remove (normalized);
1047 missingIDReferences.Add (normalized);
1049 case XmlTokenizedType.IDREFS:
1050 foreach (string id in (string []) parsedValue) {
1051 if (missingIDReferences.Contains (id))
1052 missingIDReferences.Remove (id);
1054 missingIDReferences.Add (id);
1061 private void AssessAttributeLocallyValidUse (XmlSchemaAttribute attr)
1063 // TODO: value constraint check
1064 // This is extra check than spec 3.5.4
1065 if (attr.ValidatedUse == XmlSchemaUse.Prohibited)
1066 HandleError ("Attribute " + attr.QualifiedName + " is prohibited in this context.");
1069 private void AssessEndElementSchemaValidity ()
1071 if (childParticleState == null)
1072 childParticleState = context.ParticleState;
1073 ValidateEndElementParticle (); // validate against childrens' state.
1075 context.Load (reader.Depth);
1077 // 3.3.4 Assess ElementLocallyValidElement 5: value constraints.
1078 // 3.3.4 Assess ElementLocallyValidType 3.1.3. = StringValid(3.14.4)
1079 // => ValidateEndCharacters().
1081 // Reset Identity constraints.
1082 for (int i = 0; i < keyTables.Count; i++) {
1083 XsdKeyTable keyTable = this.keyTables [i] as XsdKeyTable;
1084 if (keyTable.StartDepth == reader.Depth) {
1085 EndIdentityValidation (keyTable);
1087 for (int k = 0; k < keyTable.Entries.Count; k++) {
1088 XsdKeyEntry entry = keyTable.Entries [k] as XsdKeyEntry;
1089 // Remove finished (maybe key not found) entries.
1090 if (entry.StartDepth == reader.Depth) {
1092 keyTable.FinishedEntries.Add (entry);
1093 else if (entry.KeySequence.SourceSchemaIdentity is XmlSchemaKey)
1094 HandleError ("Key sequence is missing.");
1095 keyTable.Entries.RemoveAt (k);
1098 // Pop validated key depth to find two or more fields.
1100 foreach (XsdKeyEntryField kf in entry.KeyFields) {
1101 if (!kf.FieldFound && kf.FieldFoundDepth == reader.Depth) {
1102 kf.FieldFoundDepth = 0;
1103 kf.FieldFoundPath = null;
1110 for (int i = 0; i < keyTables.Count; i++) {
1111 XsdKeyTable keyseq = this.keyTables [i] as XsdKeyTable;
1112 if (keyseq.StartDepth == reader.Depth) {
1113 //Console.WriteLine ("Finishing table.");
1114 keyTables.RemoveAt (i);
1119 // Reset xsi:nil, if required.
1120 if (xsiNilDepth == reader.Depth)
1124 // 3.11.4 Identity Constraint Satisfied
1126 private void AssessStartIdentityConstraints ()
1128 tmpKeyrefPool.Clear ();
1129 if (context.Element != null && context.Element.Constraints.Count > 0) {
1130 // (a) Create new key sequences, if required.
1131 foreach (XmlSchemaIdentityConstraint ident in context.Element.Constraints) {
1132 XsdKeyTable seq = CreateNewKeyTable (ident);
1133 if (ident is XmlSchemaKeyref)
1134 tmpKeyrefPool.Add (seq);
1138 // (b) Evaluate current key sequences.
1139 foreach (XsdKeyTable seq in this.keyTables) {
1140 if (seq.SelectorMatches (this.elementQNameStack, reader) != null) {
1141 // creates and registers new entry.
1142 XsdKeyEntry entry = new XsdKeyEntry (seq, reader);
1143 seq.Entries.Add (entry);
1147 // (c) Evaluate field paths.
1148 foreach (XsdKeyTable seq in this.keyTables) {
1149 // If possible, create new field entry candidates.
1150 for (int i = 0; i < seq.Entries.Count; i++) {
1151 XsdKeyEntry entry = seq.Entries [i] as XsdKeyEntry;
1152 // if (entry.KeyFound)
1153 // FIXME: it should not be skipped for multiple key check!!
1156 entry.FieldMatches (this.elementQNameStack, this);
1157 } catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-(
1158 HandleError ("Identity field value is invalid against its data type.", ex);
1164 private XsdKeyTable CreateNewKeyTable (XmlSchemaIdentityConstraint ident)
1166 XsdKeyTable seq = new XsdKeyTable (ident, this);
1167 seq.StartDepth = reader.Depth;
1168 XmlSchemaKeyref keyref = ident as XmlSchemaKeyref;
1169 this.keyTables.Add (seq);
1173 private void EndIdentityValidation (XsdKeyTable seq)
1175 ArrayList errors = new ArrayList ();
1176 foreach (XsdKeyEntry entry in seq./*NotFound*/Entries) {
1179 if (seq.SourceSchemaIdentity is XmlSchemaKey)
1180 errors.Add ("line " + entry.SelectorLineNumber + "position " + entry.SelectorLinePosition);
1182 if (errors.Count > 0)
1183 HandleError ("Invalid identity constraints were found. Key was not found. "
1184 + String.Join (", ", errors.ToArray (typeof (string)) as string []));
1187 // Find reference target
1188 XmlSchemaKeyref xsdKeyref = seq.SourceSchemaIdentity as XmlSchemaKeyref;
1189 if (xsdKeyref != null) {
1190 for (int i = this.keyTables.Count - 1; i >= 0; i--) {
1191 XsdKeyTable target = this.keyTables [i] as XsdKeyTable;
1192 if (target.SourceSchemaIdentity == xsdKeyref.Target) {
1193 seq.ReferencedKey = target;
1194 foreach (XsdKeyEntry entry in seq.FinishedEntries) {
1195 foreach (XsdKeyEntry targetEntry in target.FinishedEntries) {
1196 if (entry.CompareIdentity (targetEntry)) {
1197 entry.KeyRefFound = true;
1204 if (seq.ReferencedKey == null)
1205 HandleError ("Target key was not found.");
1206 foreach (XsdKeyEntry entry in seq.FinishedEntries) {
1207 if (!entry.KeyRefFound)
1208 errors.Add (" line " + entry.SelectorLineNumber + ", position " + entry.SelectorLinePosition);
1210 if (errors.Count > 0)
1211 HandleError ("Invalid identity constraints were found. Referenced key was not found: "
1212 + String.Join (" / ", errors.ToArray (typeof (string)) as string []));
1216 // Overrided Methods
1218 public override void Close ()
1223 public override string GetAttribute (int i)
1225 switch (reader.NodeType) {
1226 case XmlNodeType.XmlDeclaration:
1227 case XmlNodeType.DocumentType:
1228 return reader.GetAttribute (i);
1231 if (reader.AttributeCount > i)
1232 reader.GetAttribute (i);
1233 int defIdx = i - nonDefaultAttributeCount;
1234 if (i < AttributeCount)
1235 return defaultAttributes [defIdx].DefaultValue;
1237 throw new ArgumentOutOfRangeException ("i", i, "Specified attribute index is out of range.");
1240 public override string GetAttribute (string name)
1242 switch (reader.NodeType) {
1243 case XmlNodeType.XmlDeclaration:
1244 case XmlNodeType.DocumentType:
1245 return reader.GetAttribute (name);
1248 string value = reader.GetAttribute (name);
1252 XmlQualifiedName qname = SplitQName (name);
1253 return GetDefaultAttribute (qname.Name, qname.Namespace);
1256 private XmlQualifiedName SplitQName (string name)
1258 if (!XmlChar.IsName (name))
1259 throw new ArgumentException ("Invalid name was specified.", "name");
1261 Exception ex = null;
1262 XmlQualifiedName qname = XmlSchemaUtil.ToQName (reader, name, out ex);
1264 return XmlQualifiedName.Empty;
1269 public override string GetAttribute (string localName, string ns)
1271 switch (reader.NodeType) {
1272 case XmlNodeType.XmlDeclaration:
1273 case XmlNodeType.DocumentType:
1274 return reader.GetAttribute (localName, ns);
1277 string value = reader.GetAttribute (localName, ns);
1281 return GetDefaultAttribute (localName, ns);
1284 private string GetDefaultAttribute (string localName, string ns)
1286 int idx = this.FindDefaultAttribute (localName, ns);
1288 return defaultAttributes [idx].ValidatedDefaultValue;
1293 private int FindDefaultAttribute (string localName, string ns)
1295 for (int i = 0; i < this.defaultAttributes.Length; i++) {
1296 XmlSchemaAttribute attr = defaultAttributes [i];
1297 if (attr.QualifiedName.Name == localName &&
1298 attr.QualifiedName.Namespace == ns)
1304 bool IXmlLineInfo.HasLineInfo ()
1306 return readerLineInfo != null && readerLineInfo.HasLineInfo ();
1309 public override string LookupNamespace (string prefix)
1311 return reader.LookupNamespace (prefix);
1314 public override void MoveToAttribute (int i)
1316 switch (reader.NodeType) {
1317 case XmlNodeType.XmlDeclaration:
1318 case XmlNodeType.DocumentType:
1319 reader.MoveToAttribute (i);
1323 currentQName = null;
1324 if (i < this.nonDefaultAttributeCount) {
1325 reader.MoveToAttribute (i);
1326 this.currentDefaultAttribute = -1;
1327 this.defaultAttributeConsumed = false;
1330 if (i < AttributeCount) {
1331 this.currentDefaultAttribute = i - nonDefaultAttributeCount;
1332 this.defaultAttributeConsumed = false;
1335 throw new ArgumentOutOfRangeException ("i", i, "Attribute index is out of range.");
1338 public override bool MoveToAttribute (string name)
1340 switch (reader.NodeType) {
1341 case XmlNodeType.XmlDeclaration:
1342 case XmlNodeType.DocumentType:
1343 return reader.MoveToAttribute (name);
1346 currentQName = null;
1347 bool b = reader.MoveToAttribute (name);
1349 this.currentDefaultAttribute = -1;
1350 this.defaultAttributeConsumed = false;
1354 XmlQualifiedName qname = SplitQName (name);
1355 return MoveToDefaultAttribute (qname.Name, qname.Namespace);
1358 public override bool MoveToAttribute (string localName, string ns)
1360 switch (reader.NodeType) {
1361 case XmlNodeType.XmlDeclaration:
1362 case XmlNodeType.DocumentType:
1363 return reader.MoveToAttribute (localName, ns);
1366 currentQName = null;
1367 bool b = reader.MoveToAttribute (localName, ns);
1369 this.currentDefaultAttribute = -1;
1370 this.defaultAttributeConsumed = false;
1374 return MoveToDefaultAttribute (localName, ns);
1377 private bool MoveToDefaultAttribute (string localName, string ns)
1379 int idx = this.FindDefaultAttribute (localName, ns);
1382 currentDefaultAttribute = idx;
1383 defaultAttributeConsumed = false;
1387 public override bool MoveToElement ()
1389 currentDefaultAttribute = -1;
1390 defaultAttributeConsumed = false;
1391 currentQName = null;
1392 return reader.MoveToElement ();
1395 public override bool MoveToFirstAttribute ()
1397 switch (reader.NodeType) {
1398 case XmlNodeType.XmlDeclaration:
1399 case XmlNodeType.DocumentType:
1400 return reader.MoveToFirstAttribute ();
1403 currentQName = null;
1404 if (this.nonDefaultAttributeCount > 0) {
1405 bool b = reader.MoveToFirstAttribute ();
1407 currentDefaultAttribute = -1;
1408 defaultAttributeConsumed = false;
1413 if (this.defaultAttributes.Length > 0) {
1414 currentDefaultAttribute = 0;
1415 defaultAttributeConsumed = false;
1422 public override bool MoveToNextAttribute ()
1424 switch (reader.NodeType) {
1425 case XmlNodeType.XmlDeclaration:
1426 case XmlNodeType.DocumentType:
1427 return reader.MoveToNextAttribute ();
1430 currentQName = null;
1431 if (currentDefaultAttribute >= 0) {
1432 if (defaultAttributes.Length == currentDefaultAttribute + 1)
1434 currentDefaultAttribute++;
1435 defaultAttributeConsumed = false;
1439 bool b = reader.MoveToNextAttribute ();
1441 currentDefaultAttribute = -1;
1442 defaultAttributeConsumed = false;
1446 if (defaultAttributes.Length > 0) {
1447 currentDefaultAttribute = 0;
1448 defaultAttributeConsumed = false;
1455 private void ExamineAdditionalSchema ()
1457 XmlSchema schema = null;
1458 string schemaLocation = reader.GetAttribute ("schemaLocation", XmlSchema.InstanceNamespace);
1459 if (schemaLocation != null) {
1460 string [] tmp = XmlSchemaDatatype.FromName ("NMTOKENS").ParseValue (schemaLocation, NameTable, null) as string [];
1461 if (tmp.Length % 2 != 0)
1462 HandleError ("Invalid schemaLocation attribute format.");
1463 for (int i = 0; i < tmp.Length; i += 2) {
1465 Uri absUri = new Uri ((this.BaseURI != "" ? new Uri (BaseURI) : null), tmp [i + 1]);
1466 XmlTextReader xtr = new XmlTextReader (absUri.ToString ());
1467 schema = XmlSchema.Read (xtr, null);
1468 } catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-(
1471 if (schema.TargetNamespace == null)
1472 schema.TargetNamespace = tmp [i];
1473 else if (schema.TargetNamespace != tmp [i])
1474 HandleError ("Specified schema has different target namespace.");
1477 if (schema != null) {
1479 schemas.Add (schema);
1480 } catch (XmlSchemaException ex) {
1485 string noNsSchemaLocation = reader.GetAttribute ("noNamespaceSchemaLocation", XmlSchema.InstanceNamespace);
1486 if (noNsSchemaLocation != null) {
1488 Uri absUri = new Uri ((this.BaseURI != "" ? new Uri (BaseURI) : null), noNsSchemaLocation);
1489 XmlTextReader xtr = new XmlTextReader (absUri.ToString ());
1490 schema = XmlSchema.Read (xtr, null);
1491 } catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-(
1493 if (schema != null && schema.TargetNamespace != null)
1494 HandleError ("Specified schema has different target namespace.");
1496 if (schema != null) {
1498 schemas.Add (schema);
1499 } catch (XmlSchemaException ex) {
1505 public override bool Read ()
1507 nonDefaultAttributeCount = 0;
1508 currentDefaultAttribute = -1;
1509 defaultAttributeConsumed = false;
1510 currentQName = null;
1511 thisElementId = null;
1512 defaultAttributes = new XmlSchemaAttribute [0];
1514 elementQNameStack.RemoveAt (elementQNameStack.Count - 1);
1518 bool result = reader.Read ();
1519 // 3.3.4 ElementLocallyValidElement 7 = Root Valid.
1520 if (!result && missingIDReferences.Count > 0)
1521 HandleError ("There are missing ID references: " +
1523 this.missingIDReferences.ToArray (typeof (string)) as string []));
1525 switch (reader.NodeType) {
1526 case XmlNodeType.Element:
1527 nonDefaultAttributeCount = reader.AttributeCount;
1529 if (reader.Depth == 0)
1530 ExamineAdditionalSchema ();
1532 this.elementQNameStack.Add (new XmlQualifiedName (reader.LocalName, reader.NamespaceURI));
1534 // If there is no schema information, then no validation is performed.
1535 if (schemas.Count == 0)
1538 // context.Load (reader.Depth);
1539 if (skipValidationDepth < 0 || reader.Depth <= skipValidationDepth) {
1540 if (shouldValidateCharacters) {
1541 ValidateEndCharacters ();
1542 shouldValidateCharacters = false;
1544 AssessStartElementSchemaValidity ();
1545 storedCharacters.Length = 0;
1550 if (reader.IsEmptyElement)
1551 goto case XmlNodeType.EndElement;
1553 shouldValidateCharacters = true;
1555 case XmlNodeType.EndElement:
1556 if (reader.Depth == skipValidationDepth) {
1557 skipValidationDepth = -1;
1560 // context.Load (reader.Depth);
1561 if (shouldValidateCharacters) {
1562 ValidateEndCharacters ();
1563 shouldValidateCharacters = false;
1565 AssessEndElementSchemaValidity ();
1567 storedCharacters.Length = 0;
1568 childParticleState = null;
1572 case XmlNodeType.CDATA:
1573 case XmlNodeType.SignificantWhitespace:
1574 case XmlNodeType.Text:
1575 XmlSchemaComplexType ct = context.ActualType as XmlSchemaComplexType;
1576 if (ct != null && storedCharacters.Length > 0) {
1577 switch (ct.ContentType) {
1578 case XmlSchemaContentType.ElementOnly:
1579 case XmlSchemaContentType.Empty:
1580 HandleError ("Not allowed character content was found.");
1585 ValidateCharacters ();
1592 public override bool ReadAttributeValue ()
1594 if (currentDefaultAttribute < 0)
1595 return reader.ReadAttributeValue ();
1597 if (this.defaultAttributeConsumed)
1600 defaultAttributeConsumed = true;
1605 public override string ReadInnerXml ()
1607 // MS.NET 1.0 has a serious bug here. It skips validation.
1608 return reader.ReadInnerXml ();
1611 public override string ReadOuterXml ()
1613 // MS.NET 1.0 has a serious bug here. It skips validation.
1614 return reader.ReadOuterXml ();
1618 // XmlReader.ReadString() should call derived this.Read().
1619 public override string ReadString ()
1622 return reader.ReadString ();
1624 return base.ReadString ();
1628 // This class itself does not have this feature.
1629 public override void ResolveEntity ()
1631 reader.ResolveEntity ();
1634 internal class XsdValidationContext
1636 Hashtable contextStack;
1638 public XsdValidationContext ()
1640 contextStack = new Hashtable ();
1643 // Some of them might be missing (See the spec section 5.3, and also 3.3.4).
1644 public XmlSchemaElement Element;
1645 public XsdValidationState ParticleState;
1646 public XmlSchemaAttribute [] DefaultAttributes;
1648 // Some of them might be missing (See the spec section 5.3).
1649 public object SchemaType;
1651 public object LocalTypeDefinition;
1653 public object ActualType {
1655 if (LocalTypeDefinition != null)
1656 return LocalTypeDefinition;
1662 public void Clear ()
1666 ParticleState = null;
1667 LocalTypeDefinition = null;
1670 public void PushScope (int depth)
1672 contextStack [depth] = this.MemberwiseClone ();
1675 public void PopScope (int depth)
1678 contextStack.Remove (depth + 1);
1681 public void Load (int depth)
1684 XsdValidationContext restored = (XsdValidationContext) contextStack [depth];
1685 if (restored != null) {
1686 this.Element = restored.Element;
1687 this.ParticleState = restored.ParticleState;
1688 this.SchemaType = restored.SchemaType;
1689 this.LocalTypeDefinition = restored.LocalTypeDefinition;
1695 internal class XsdValidityState
1697 ArrayList currentParticles = new ArrayList ();
1698 ArrayList occured = new ArrayList ();
1699 Hashtable xsAllConsumed = new Hashtable ();
1700 XmlSchemaParticle parciele;
1703 public XsdValidityState (XmlSchemaParticle particle)
1705 this.parciele = particle;
1706 currentParticles.Add (particle);