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 static 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 [ns];
439 if (matches != null) {
440 XmlSchemaElement result = target.Elements [new XmlQualifiedName (name, ns)] 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 /* Don't forget to validate against inherited type's facets
624 * Could we simplify this by assuming that the basetype will also
627 // mmm, will check later.
628 XmlSchemaSimpleType baseType = str.ActualBaseSchemaType as XmlSchemaSimpleType;
629 if (baseType != null) {
630 AssessStringValid(baseType, dt, normalized);
632 if (!str.ValidateValueWithFacets (normalized, NameTable)) {
633 HandleError ("Specified value was invalid against the facets.");
637 validatedDatatype = st.Datatype;
641 if (validatedDatatype != null) {
643 validatedDatatype.ParseValue (value, NameTable, ParserContext.NamespaceManager);
644 } catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-(
645 HandleError ("Invalidly typed data was specified.", ex);
650 private object GetLocalTypeDefinition (string name)
652 object xsiType = null;
653 XmlQualifiedName typeQName = QualifyName (name);
654 if (typeQName.Namespace == XmlSchema.Namespace) {
655 if (typeQName.Name == "anyType")
656 xsiType = XmlSchemaComplexType.AnyType;
658 xsiType = XmlSchemaDatatype.FromName (typeQName);
661 xsiType = FindType (typeQName);
665 // It is common to ElementLocallyValid::4 and SchemaValidityAssessment::1.2.1.2.4
666 private void AssessLocalTypeDerivationOK (object xsiType, object baseType, XmlSchemaDerivationMethod flag)
668 XmlSchemaType xsiSchemaType = xsiType as XmlSchemaType;
669 XmlSchemaComplexType baseComplexType = baseType as XmlSchemaComplexType;
670 XmlSchemaComplexType xsiComplexType = xsiSchemaType as XmlSchemaComplexType;
671 if (xsiType != baseType) {
672 // Extracted (not extraneous) check for 3.4.6 TypeDerivationOK.
673 if (baseComplexType != null)
674 flag |= baseComplexType.BlockResolved;
675 if (flag == XmlSchemaDerivationMethod.All) {
676 HandleError ("Prohibited element type substitution.");
678 } else if (xsiSchemaType != null && (flag & xsiSchemaType.DerivedBy) != 0) {
679 HandleError ("Prohibited element type substitution.");
684 if (xsiComplexType != null)
686 xsiComplexType.ValidateTypeDerivationOK (baseType, null, null);
687 } catch (XmlSchemaException ex) {
688 // HandleError ("Locally specified schema complex type derivation failed. " + ex.Message, ex);
692 XmlSchemaSimpleType xsiSimpleType = xsiType as XmlSchemaSimpleType;
693 if (xsiSimpleType != null) {
695 xsiSimpleType.ValidateTypeDerivationOK (baseType, null, null, true);
696 } catch (XmlSchemaException ex) {
697 // HandleError ("Locally specified schema simple type derivation failed. " + ex.Message, ex);
701 else if (xsiType is XmlSchemaDatatype) {
705 HandleError ("Primitive data type cannot be derived type using xsi:type specification.");
709 // Section 3.3.4 of the spec.
710 private void AssessStartElementSchemaValidity ()
712 // If the reader is inside xsi:nil (and failed on validation),
713 // then simply skip its content.
714 if (xsiNilDepth >= 0 && xsiNilDepth < reader.Depth)
715 HandleError ("Element item appeared, while current element context is nil.");
717 context.Load (reader.Depth);
718 if (childParticleState != null) {
719 context.ParticleState = childParticleState;
720 childParticleState = null;
723 // If validation state exists, then first assess particle validity.
724 if (context.ParticleState != null) {
725 ValidateStartElementParticle ();
728 string xsiNilValue = GetAttribute ("nil", XmlSchema.InstanceNamespace);
729 if (xsiNilValue != null)
730 xsiNilValue = xsiNilValue.Trim (XmlChar.WhitespaceChars);
731 bool isXsiNil = xsiNilValue == "true";
732 if (isXsiNil && this.xsiNilDepth < 0)
733 xsiNilDepth = reader.Depth;
735 // [Schema Validity Assessment (Element) 1.2]
736 // Evaluate "local type definition" from xsi:type.
737 // (See spec 3.3.4 Schema Validity Assessment (Element) 1.2.1.2.3.
738 // Note that Schema Validity Assessment(Element) 1.2 takes
739 // precedence than 1.1 of that.
741 string xsiTypeName = reader.GetAttribute ("type", XmlSchema.InstanceNamespace);
742 if (xsiTypeName != null) {
743 xsiTypeName = xsiTypeName.Trim (XmlChar.WhitespaceChars);
744 object xsiType = GetLocalTypeDefinition (xsiTypeName);
746 HandleError ("The instance type was not found: " + xsiTypeName + " .");
748 XmlSchemaType xsiSchemaType = xsiType as XmlSchemaType;
749 if (xsiSchemaType != null && this.context.Element != null) {
750 XmlSchemaType elemBaseType = context.Element.ElementType as XmlSchemaType;
751 if (elemBaseType != null && (xsiSchemaType.DerivedBy & elemBaseType.FinalResolved) != 0)
752 HandleError ("The instance type is prohibited by the type of the context element.");
753 if (elemBaseType != xsiType && (xsiSchemaType.DerivedBy & this.context.Element.BlockResolved) != 0)
754 HandleError ("The instance type is prohibited by the context element.");
756 XmlSchemaComplexType xsiComplexType = xsiType as XmlSchemaComplexType;
757 if (xsiComplexType != null && xsiComplexType.IsAbstract)
758 HandleError ("The instance type is abstract: " + xsiTypeName + " .");
760 // If current schema type exists, then this xsi:type must be
761 // valid extension of that type. See 1.2.1.2.4.
762 if (context.Element != null) {
763 // FIXME: supply *correct* base type
764 AssessLocalTypeDerivationOK (xsiType, context.Element.ElementType, context.Element.BlockResolved);
766 AssessStartElementLocallyValidType (xsiType); // 1.2.2:
767 context.LocalTypeDefinition = xsiType;
772 // Create Validation Root, if not exist.
773 // [Schema Validity Assessment (Element) 1.1]
774 if (context.Element == null)
775 context.Element = FindElement (reader.LocalName, reader.NamespaceURI);
776 if (context.Element != null) {
777 if (xsiTypeName == null) {
778 context.SchemaType = context.Element.ElementType;
779 AssessElementLocallyValidElement (context.Element, xsiNilValue); // 1.1.2
783 switch (stateManager.ProcessContents) {
784 case XmlSchemaContentProcessing.Skip:
786 case XmlSchemaContentProcessing.Lax:
788 schema = schemas [reader.NamespaceURI];
789 if (schema != null && !schema.missedSubComponents)
790 HandleError ("Element declaration for " + reader.LocalName + " is missing.");
794 schema = schemas [reader.NamespaceURI];
795 if (xsiTypeName == null && (schema == null || !schema.missedSubComponents))
796 HandleError ("Element declaration for " + reader.LocalName + " is missing.");
801 if (stateManager.ProcessContents == XmlSchemaContentProcessing.Skip)
802 skipValidationDepth = reader.Depth;
804 // Finally, create child particle state.
805 XmlSchemaComplexType xsComplexType = SchemaType as XmlSchemaComplexType;
806 if (xsComplexType != null)
807 childParticleState = stateManager.Create (xsComplexType.ContentTypeParticle);
808 else if (stateManager.ProcessContents == XmlSchemaContentProcessing.Lax)
809 childParticleState = stateManager.Create (XmlSchemaAny.AnyTypeContent);
811 childParticleState = stateManager.Create (XmlSchemaParticle.Empty);
813 AssessStartIdentityConstraints ();
815 context.PushScope (reader.Depth);
818 // 3.3.4 Element Locally Valid (Element)
819 private void AssessElementLocallyValidElement (XmlSchemaElement element, string xsiNilValue)
821 XmlQualifiedName qname = new XmlQualifiedName (reader.LocalName, reader.NamespaceURI);
824 HandleError ("Element declaration is required for " + qname);
826 if (element.actualIsAbstract)
827 HandleError ("Abstract element declaration was specified for " + qname);
829 if (!element.actualIsNillable && xsiNilValue != null)
830 HandleError ("This element declaration is not nillable: " + qname);
832 // Note that 3.2.1 xsi:nil constraints are to be validated in
833 else if (xsiNilValue == "true") {
834 // AssessElementSchemaValidity() and ValidateCharacters()
836 if (element.ValidatedFixedValue != null)
837 HandleError ("Schema instance nil was specified, where the element declaration for " + qname + "has fixed value constraints.");
840 string xsiType = reader.GetAttribute ("type", XmlSchema.InstanceNamespace);
841 if (xsiType != null) {
842 context.LocalTypeDefinition = GetLocalTypeDefinition (xsiType);
843 AssessLocalTypeDerivationOK (context.LocalTypeDefinition, element.ElementType, element.BlockResolved);
846 // 5 Not all things cannot be assessed here.
847 // It is common to 5.1 and 5.2
848 if (element.ElementType != null)
849 AssessStartElementLocallyValidType (SchemaType);
851 // 6. should be out from here.
852 // See invokation of AssessStartIdentityConstraints().
854 // 7 is going to be validated in Read() (in case of xmlreader's EOF).
857 // 3.3.4 Element Locally Valid (Type)
858 private void AssessStartElementLocallyValidType (object schemaType)
860 if (schemaType == null) { // 1.
861 HandleError ("Schema type does not exist.");
864 XmlSchemaComplexType cType = schemaType as XmlSchemaComplexType;
865 XmlSchemaSimpleType sType = schemaType as XmlSchemaSimpleType;
868 while (reader.MoveToNextAttribute ()) {
869 if (reader.NamespaceURI == XmlNamespaceManager.XmlnsXmlns)
871 if (reader.NamespaceURI != XmlSchema.InstanceNamespace)
872 HandleError ("Current simple type cannot accept attributes other than schema instance namespace.");
873 switch (reader.LocalName) {
876 case "schemaLocation":
877 case "noNamespaceSchemaLocation":
880 HandleError ("Unknown schema instance namespace attribute: " + reader.LocalName);
884 reader.MoveToElement ();
885 // 3.1.2 and 3.1.3 cannot be assessed here.
886 } else if (cType != null) {
887 if (cType.IsAbstract) { // 2.
888 HandleError ("Target complex type is abstract.");
892 AssessElementLocallyValidComplexType (cType);
896 // 3.4.4 Element Locally Valid (Complex Type)
897 // TODO ("wild IDs constraints.")
898 private void AssessElementLocallyValidComplexType (XmlSchemaComplexType cType)
901 if (cType.IsAbstract)
902 HandleError ("Target complex type is abstract.");
904 // 2 (xsi:nil and content prohibition)
905 // See AssessStartElementSchemaValidity() and ValidateCharacters()
907 string elementNs = reader.NamespaceURI;
908 // 3. attribute uses and
910 while (reader.MoveToNextAttribute ()) {
911 if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/")
913 else if (reader.NamespaceURI == XmlSchema.InstanceNamespace)
915 XmlQualifiedName qname = new XmlQualifiedName (reader.LocalName, reader.NamespaceURI);
916 object attMatch = FindAttributeDeclaration (cType, qname, elementNs);
917 if (attMatch == null)
918 HandleError ("Attribute declaration was not found for " + qname);
920 XmlSchemaAttribute attdecl = attMatch as XmlSchemaAttribute;
921 if (attdecl == null) { // i.e. anyAttribute
922 XmlSchemaAnyAttribute anyAttrMatch = attMatch as XmlSchemaAnyAttribute;
924 AssessAttributeLocallyValidUse (attdecl);
925 AssessAttributeLocallyValid (attdecl, true);
929 reader.MoveToElement ();
931 // Collect default attributes.
933 // FIXME: FixedValue check maybe extraneous.
934 foreach (XmlSchemaAttribute attr in cType.AttributeUses) {
935 if (reader [attr.QualifiedName.Name, attr.QualifiedName.Namespace] == null) {
936 if (attr.ValidatedUse == XmlSchemaUse.Required &&
937 attr.ValidatedFixedValue == null)
938 HandleError ("Required attribute " + attr.QualifiedName + " was not found.");
939 else if (attr.ValidatedDefaultValue != null)
940 defaultAttributesCache.Add (attr);
943 defaultAttributes = (XmlSchemaAttribute [])
944 defaultAttributesCache.ToArray (typeof (XmlSchemaAttribute));
945 context.DefaultAttributes = defaultAttributes;
946 defaultAttributesCache.Clear ();
947 // 5. wild IDs was already checked above.
950 // Spec 3.10.4 Item Valid (Wildcard)
951 private bool AttributeWildcardItemValid (XmlSchemaAnyAttribute anyAttr, XmlQualifiedName qname)
953 if (anyAttr.HasValueAny)
955 if (anyAttr.HasValueOther && (anyAttr.TargetNamespace == "" || reader.NamespaceURI != anyAttr.TargetNamespace))
957 if (anyAttr.HasValueTargetNamespace && reader.NamespaceURI == anyAttr.TargetNamespace)
959 if (anyAttr.HasValueLocal && reader.NamespaceURI == "")
961 foreach (string ns in anyAttr.ResolvedNamespaces)
962 if (ns == reader.NamespaceURI)
967 private XmlSchemaObject FindAttributeDeclaration (XmlSchemaComplexType cType,
968 XmlQualifiedName qname, string elementNs)
970 XmlSchemaObject result = cType.AttributeUses [qname];
973 if (cType.AttributeWildcard == null)
976 if (!AttributeWildcardItemValid (cType.AttributeWildcard, qname))
979 if (cType.AttributeWildcard.ProcessContents == XmlSchemaContentProcessing.Skip)
980 return cType.AttributeWildcard;
981 foreach (XmlSchema schema in schemas) {
982 foreach (XmlSchemaAttribute attr in schema.Attributes)
983 if (attr.QualifiedName == qname)
986 if (cType.AttributeWildcard.ProcessContents == XmlSchemaContentProcessing.Lax)
987 return cType.AttributeWildcard;
992 // 3.2.4 Attribute Locally Valid and 3.4.4 - 5.wildIDs
994 private void AssessAttributeLocallyValid (XmlSchemaAttribute attr, bool checkWildIDs)
997 switch (reader.NamespaceURI) {
998 case XmlNamespaceManager.XmlnsXml:
999 case XmlNamespaceManager.XmlnsXmlns:
1000 case XmlSchema.InstanceNamespace:
1004 if (attr.AttributeType == null)
1005 HandleError ("Attribute type is missing for " + attr.QualifiedName);
1006 XmlSchemaDatatype dt = attr.AttributeType as XmlSchemaDatatype;
1008 dt = ((XmlSchemaSimpleType) attr.AttributeType).Datatype;
1009 // It is a bit heavy process, so let's omit as long as possible ;-)
1010 if (dt != XmlSchemaSimpleType.AnySimpleType || attr.ValidatedFixedValue != null) {
1011 string normalized = dt.Normalize (reader.Value);
1012 object parsedValue = null;
1014 dt.ParseValue (normalized, reader.NameTable, this.ParserContext.NamespaceManager);
1015 } catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-(
1016 HandleError ("Attribute value is invalid against its data type " + dt.TokenizedType, ex);
1018 if (attr.ValidatedFixedValue != null && attr.ValidatedFixedValue != normalized)
1019 HandleError ("The value of the attribute " + attr.QualifiedName + " does not match with its fixed value.");
1020 // FIXME: this is extraneous checks in 3.2.4 Attribute Locally Valid.
1022 AssessEachAttributeIdentityConstraint (dt, normalized, parsedValue);
1026 private void AssessEachAttributeIdentityConstraint (XmlSchemaDatatype dt,
1027 string normalized, object parsedValue)
1029 // Get normalized value and (if required) parsedValue if missing.
1030 switch (dt.TokenizedType) {
1031 case XmlTokenizedType.IDREFS:
1032 if (normalized == null)
1033 normalized = dt.Normalize (reader.Value);
1034 if (parsedValue == null)
1035 parsedValue = dt.ParseValue (normalized, reader.NameTable, ParserContext.NamespaceManager);
1037 case XmlTokenizedType.ID:
1038 case XmlTokenizedType.IDREF:
1039 if (normalized == null)
1040 normalized = dt.Normalize (reader.Value);
1044 // Validate identity constraints.
1045 switch (dt.TokenizedType) {
1046 case XmlTokenizedType.ID:
1047 if (thisElementId != null)
1048 HandleError ("ID type attribute was already assigned in the containing element.");
1049 thisElementId = normalized;
1050 idList.Add (normalized);
1052 case XmlTokenizedType.IDREF:
1053 if (missingIDReferences.Contains (normalized))
1054 missingIDReferences.Remove (normalized);
1056 missingIDReferences.Add (normalized);
1058 case XmlTokenizedType.IDREFS:
1059 foreach (string id in (string []) parsedValue) {
1060 if (missingIDReferences.Contains (id))
1061 missingIDReferences.Remove (id);
1063 missingIDReferences.Add (id);
1070 private void AssessAttributeLocallyValidUse (XmlSchemaAttribute attr)
1072 // TODO: value constraint check
1073 // This is extra check than spec 3.5.4
1074 if (attr.ValidatedUse == XmlSchemaUse.Prohibited)
1075 HandleError ("Attribute " + attr.QualifiedName + " is prohibited in this context.");
1078 private void AssessEndElementSchemaValidity ()
1080 if (childParticleState == null)
1081 childParticleState = context.ParticleState;
1082 ValidateEndElementParticle (); // validate against childrens' state.
1084 context.Load (reader.Depth);
1086 // 3.3.4 Assess ElementLocallyValidElement 5: value constraints.
1087 // 3.3.4 Assess ElementLocallyValidType 3.1.3. = StringValid(3.14.4)
1088 // => ValidateEndCharacters().
1090 // Reset Identity constraints.
1091 for (int i = 0; i < keyTables.Count; i++) {
1092 XsdKeyTable keyTable = this.keyTables [i] as XsdKeyTable;
1093 if (keyTable.StartDepth == reader.Depth) {
1094 EndIdentityValidation (keyTable);
1096 for (int k = 0; k < keyTable.Entries.Count; k++) {
1097 XsdKeyEntry entry = keyTable.Entries [k] as XsdKeyEntry;
1098 // Remove finished (maybe key not found) entries.
1099 if (entry.StartDepth == reader.Depth) {
1101 keyTable.FinishedEntries.Add (entry);
1102 else if (entry.KeySequence.SourceSchemaIdentity is XmlSchemaKey)
1103 HandleError ("Key sequence is missing.");
1104 keyTable.Entries.RemoveAt (k);
1107 // Pop validated key depth to find two or more fields.
1109 foreach (XsdKeyEntryField kf in entry.KeyFields) {
1110 if (!kf.FieldFound && kf.FieldFoundDepth == reader.Depth) {
1111 kf.FieldFoundDepth = 0;
1112 kf.FieldFoundPath = null;
1119 for (int i = 0; i < keyTables.Count; i++) {
1120 XsdKeyTable keyseq = this.keyTables [i] as XsdKeyTable;
1121 if (keyseq.StartDepth == reader.Depth) {
1122 //Console.WriteLine ("Finishing table.");
1123 keyTables.RemoveAt (i);
1128 // Reset xsi:nil, if required.
1129 if (xsiNilDepth == reader.Depth)
1133 // 3.11.4 Identity Constraint Satisfied
1135 private void AssessStartIdentityConstraints ()
1137 tmpKeyrefPool.Clear ();
1138 if (context.Element != null && context.Element.Constraints.Count > 0) {
1139 // (a) Create new key sequences, if required.
1140 foreach (XmlSchemaIdentityConstraint ident in context.Element.Constraints) {
1141 XsdKeyTable seq = CreateNewKeyTable (ident);
1142 if (ident is XmlSchemaKeyref)
1143 tmpKeyrefPool.Add (seq);
1147 // (b) Evaluate current key sequences.
1148 foreach (XsdKeyTable seq in this.keyTables) {
1149 if (seq.SelectorMatches (this.elementQNameStack, reader) != null) {
1150 // creates and registers new entry.
1151 XsdKeyEntry entry = new XsdKeyEntry (seq, reader);
1152 seq.Entries.Add (entry);
1156 // (c) Evaluate field paths.
1157 foreach (XsdKeyTable seq in this.keyTables) {
1158 // If possible, create new field entry candidates.
1159 for (int i = 0; i < seq.Entries.Count; i++) {
1160 XsdKeyEntry entry = seq.Entries [i] as XsdKeyEntry;
1161 // if (entry.KeyFound)
1162 // FIXME: it should not be skipped for multiple key check!!
1165 entry.FieldMatches (this.elementQNameStack, this);
1166 } catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-(
1167 HandleError ("Identity field value is invalid against its data type.", ex);
1173 private XsdKeyTable CreateNewKeyTable (XmlSchemaIdentityConstraint ident)
1175 XsdKeyTable seq = new XsdKeyTable (ident, this);
1176 seq.StartDepth = reader.Depth;
1177 XmlSchemaKeyref keyref = ident as XmlSchemaKeyref;
1178 this.keyTables.Add (seq);
1182 private void EndIdentityValidation (XsdKeyTable seq)
1184 ArrayList errors = new ArrayList ();
1185 foreach (XsdKeyEntry entry in seq./*NotFound*/Entries) {
1188 if (seq.SourceSchemaIdentity is XmlSchemaKey)
1189 errors.Add ("line " + entry.SelectorLineNumber + "position " + entry.SelectorLinePosition);
1191 if (errors.Count > 0)
1192 HandleError ("Invalid identity constraints were found. Key was not found. "
1193 + String.Join (", ", errors.ToArray (typeof (string)) as string []));
1196 // Find reference target
1197 XmlSchemaKeyref xsdKeyref = seq.SourceSchemaIdentity as XmlSchemaKeyref;
1198 if (xsdKeyref != null) {
1199 for (int i = this.keyTables.Count - 1; i >= 0; i--) {
1200 XsdKeyTable target = this.keyTables [i] as XsdKeyTable;
1201 if (target.SourceSchemaIdentity == xsdKeyref.Target) {
1202 seq.ReferencedKey = target;
1203 foreach (XsdKeyEntry entry in seq.FinishedEntries) {
1204 foreach (XsdKeyEntry targetEntry in target.FinishedEntries) {
1205 if (entry.CompareIdentity (targetEntry)) {
1206 entry.KeyRefFound = true;
1213 if (seq.ReferencedKey == null)
1214 HandleError ("Target key was not found.");
1215 foreach (XsdKeyEntry entry in seq.FinishedEntries) {
1216 if (!entry.KeyRefFound)
1217 errors.Add (" line " + entry.SelectorLineNumber + ", position " + entry.SelectorLinePosition);
1219 if (errors.Count > 0)
1220 HandleError ("Invalid identity constraints were found. Referenced key was not found: "
1221 + String.Join (" / ", errors.ToArray (typeof (string)) as string []));
1225 // Overrided Methods
1227 public override void Close ()
1232 public override string GetAttribute (int i)
1234 switch (reader.NodeType) {
1235 case XmlNodeType.XmlDeclaration:
1236 case XmlNodeType.DocumentType:
1237 return reader.GetAttribute (i);
1240 if (reader.AttributeCount > i)
1241 reader.GetAttribute (i);
1242 int defIdx = i - nonDefaultAttributeCount;
1243 if (i < AttributeCount)
1244 return defaultAttributes [defIdx].DefaultValue;
1246 throw new ArgumentOutOfRangeException ("i", i, "Specified attribute index is out of range.");
1249 public override string GetAttribute (string name)
1251 switch (reader.NodeType) {
1252 case XmlNodeType.XmlDeclaration:
1253 case XmlNodeType.DocumentType:
1254 return reader.GetAttribute (name);
1257 string value = reader.GetAttribute (name);
1261 XmlQualifiedName qname = SplitQName (name);
1262 return GetDefaultAttribute (qname.Name, qname.Namespace);
1265 private XmlQualifiedName SplitQName (string name)
1267 if (!XmlChar.IsName (name))
1268 throw new ArgumentException ("Invalid name was specified.", "name");
1270 Exception ex = null;
1271 XmlQualifiedName qname = XmlSchemaUtil.ToQName (reader, name, out ex);
1273 return XmlQualifiedName.Empty;
1278 public override string GetAttribute (string localName, string ns)
1280 switch (reader.NodeType) {
1281 case XmlNodeType.XmlDeclaration:
1282 case XmlNodeType.DocumentType:
1283 return reader.GetAttribute (localName, ns);
1286 string value = reader.GetAttribute (localName, ns);
1290 return GetDefaultAttribute (localName, ns);
1293 private string GetDefaultAttribute (string localName, string ns)
1295 int idx = this.FindDefaultAttribute (localName, ns);
1297 return defaultAttributes [idx].ValidatedDefaultValue;
1302 private int FindDefaultAttribute (string localName, string ns)
1304 for (int i = 0; i < this.defaultAttributes.Length; i++) {
1305 XmlSchemaAttribute attr = defaultAttributes [i];
1306 if (attr.QualifiedName.Name == localName &&
1307 attr.QualifiedName.Namespace == ns)
1313 bool IXmlLineInfo.HasLineInfo ()
1315 return readerLineInfo != null && readerLineInfo.HasLineInfo ();
1318 public override string LookupNamespace (string prefix)
1320 return reader.LookupNamespace (prefix);
1323 public override void MoveToAttribute (int i)
1325 switch (reader.NodeType) {
1326 case XmlNodeType.XmlDeclaration:
1327 case XmlNodeType.DocumentType:
1328 reader.MoveToAttribute (i);
1332 currentQName = null;
1333 if (i < this.nonDefaultAttributeCount) {
1334 reader.MoveToAttribute (i);
1335 this.currentDefaultAttribute = -1;
1336 this.defaultAttributeConsumed = false;
1339 if (i < AttributeCount) {
1340 this.currentDefaultAttribute = i - nonDefaultAttributeCount;
1341 this.defaultAttributeConsumed = false;
1344 throw new ArgumentOutOfRangeException ("i", i, "Attribute index is out of range.");
1347 public override bool MoveToAttribute (string name)
1349 switch (reader.NodeType) {
1350 case XmlNodeType.XmlDeclaration:
1351 case XmlNodeType.DocumentType:
1352 return reader.MoveToAttribute (name);
1355 currentQName = null;
1356 bool b = reader.MoveToAttribute (name);
1358 this.currentDefaultAttribute = -1;
1359 this.defaultAttributeConsumed = false;
1363 XmlQualifiedName qname = SplitQName (name);
1364 return MoveToDefaultAttribute (qname.Name, qname.Namespace);
1367 public override bool MoveToAttribute (string localName, string ns)
1369 switch (reader.NodeType) {
1370 case XmlNodeType.XmlDeclaration:
1371 case XmlNodeType.DocumentType:
1372 return reader.MoveToAttribute (localName, ns);
1375 currentQName = null;
1376 bool b = reader.MoveToAttribute (localName, ns);
1378 this.currentDefaultAttribute = -1;
1379 this.defaultAttributeConsumed = false;
1383 return MoveToDefaultAttribute (localName, ns);
1386 private bool MoveToDefaultAttribute (string localName, string ns)
1388 int idx = this.FindDefaultAttribute (localName, ns);
1391 currentDefaultAttribute = idx;
1392 defaultAttributeConsumed = false;
1396 public override bool MoveToElement ()
1398 currentDefaultAttribute = -1;
1399 defaultAttributeConsumed = false;
1400 currentQName = null;
1401 return reader.MoveToElement ();
1404 public override bool MoveToFirstAttribute ()
1406 switch (reader.NodeType) {
1407 case XmlNodeType.XmlDeclaration:
1408 case XmlNodeType.DocumentType:
1409 return reader.MoveToFirstAttribute ();
1412 currentQName = null;
1413 if (this.nonDefaultAttributeCount > 0) {
1414 bool b = reader.MoveToFirstAttribute ();
1416 currentDefaultAttribute = -1;
1417 defaultAttributeConsumed = false;
1422 if (this.defaultAttributes.Length > 0) {
1423 currentDefaultAttribute = 0;
1424 defaultAttributeConsumed = false;
1431 public override bool MoveToNextAttribute ()
1433 switch (reader.NodeType) {
1434 case XmlNodeType.XmlDeclaration:
1435 case XmlNodeType.DocumentType:
1436 return reader.MoveToNextAttribute ();
1439 currentQName = null;
1440 if (currentDefaultAttribute >= 0) {
1441 if (defaultAttributes.Length == currentDefaultAttribute + 1)
1443 currentDefaultAttribute++;
1444 defaultAttributeConsumed = false;
1448 bool b = reader.MoveToNextAttribute ();
1450 currentDefaultAttribute = -1;
1451 defaultAttributeConsumed = false;
1455 if (defaultAttributes.Length > 0) {
1456 currentDefaultAttribute = 0;
1457 defaultAttributeConsumed = false;
1464 private void ExamineAdditionalSchema ()
1466 XmlSchema schema = null;
1467 string schemaLocation = reader.GetAttribute ("schemaLocation", XmlSchema.InstanceNamespace);
1468 if (schemaLocation != null) {
1469 string [] tmp = XmlSchemaDatatype.FromName ("NMTOKENS").ParseValue (schemaLocation, NameTable, null) as string [];
1470 if (tmp.Length % 2 != 0)
1471 HandleError ("Invalid schemaLocation attribute format.");
1472 for (int i = 0; i < tmp.Length; i += 2) {
1474 Uri absUri = new Uri ((this.BaseURI != "" ? new Uri (BaseURI) : null), tmp [i + 1]);
1475 XmlTextReader xtr = new XmlTextReader (absUri.ToString ());
1476 schema = XmlSchema.Read (xtr, null);
1477 } catch (Exception) { // FIXME: (wishlist) It is bad manner ;-(
1480 if (schema.TargetNamespace == null)
1481 schema.TargetNamespace = tmp [i];
1482 else if (schema.TargetNamespace != tmp [i])
1483 HandleError ("Specified schema has different target namespace.");
1486 if (schema != null) {
1488 schemas.Add (schema);
1489 } catch (XmlSchemaException ex) {
1494 string noNsSchemaLocation = reader.GetAttribute ("noNamespaceSchemaLocation", XmlSchema.InstanceNamespace);
1495 if (noNsSchemaLocation != null) {
1497 Uri absUri = new Uri ((this.BaseURI != "" ? new Uri (BaseURI) : null), noNsSchemaLocation);
1498 XmlTextReader xtr = new XmlTextReader (absUri.ToString ());
1499 schema = XmlSchema.Read (xtr, null);
1500 } catch (Exception) { // FIXME: (wishlist) It is bad manner ;-(
1502 if (schema != null && schema.TargetNamespace != null)
1503 HandleError ("Specified schema has different target namespace.");
1505 if (schema != null) {
1507 schemas.Add (schema);
1508 } catch (XmlSchemaException ex) {
1514 public override bool Read ()
1516 nonDefaultAttributeCount = 0;
1517 currentDefaultAttribute = -1;
1518 defaultAttributeConsumed = false;
1519 currentQName = null;
1520 thisElementId = null;
1521 defaultAttributes = new XmlSchemaAttribute [0];
1523 elementQNameStack.RemoveAt (elementQNameStack.Count - 1);
1527 bool result = reader.Read ();
1528 // 3.3.4 ElementLocallyValidElement 7 = Root Valid.
1529 if (!result && missingIDReferences.Count > 0)
1530 HandleError ("There are missing ID references: " +
1532 this.missingIDReferences.ToArray (typeof (string)) as string []));
1534 switch (reader.NodeType) {
1535 case XmlNodeType.Element:
1536 nonDefaultAttributeCount = reader.AttributeCount;
1538 if (reader.Depth == 0)
1539 ExamineAdditionalSchema ();
1541 this.elementQNameStack.Add (new XmlQualifiedName (reader.LocalName, reader.NamespaceURI));
1543 // If there is no schema information, then no validation is performed.
1544 if (schemas.Count == 0)
1547 // context.Load (reader.Depth);
1548 if (skipValidationDepth < 0 || reader.Depth <= skipValidationDepth) {
1549 if (shouldValidateCharacters) {
1550 ValidateEndCharacters ();
1551 shouldValidateCharacters = false;
1553 AssessStartElementSchemaValidity ();
1554 storedCharacters.Length = 0;
1559 if (reader.IsEmptyElement)
1560 goto case XmlNodeType.EndElement;
1562 shouldValidateCharacters = true;
1564 case XmlNodeType.EndElement:
1565 if (reader.Depth == skipValidationDepth) {
1566 skipValidationDepth = -1;
1569 // context.Load (reader.Depth);
1570 if (shouldValidateCharacters) {
1571 ValidateEndCharacters ();
1572 shouldValidateCharacters = false;
1574 AssessEndElementSchemaValidity ();
1576 storedCharacters.Length = 0;
1577 childParticleState = null;
1581 case XmlNodeType.CDATA:
1582 case XmlNodeType.SignificantWhitespace:
1583 case XmlNodeType.Text:
1584 XmlSchemaComplexType ct = context.ActualType as XmlSchemaComplexType;
1585 if (ct != null && storedCharacters.Length > 0) {
1586 switch (ct.ContentType) {
1587 case XmlSchemaContentType.ElementOnly:
1588 case XmlSchemaContentType.Empty:
1589 HandleError ("Not allowed character content was found.");
1594 ValidateCharacters ();
1601 public override bool ReadAttributeValue ()
1603 if (currentDefaultAttribute < 0)
1604 return reader.ReadAttributeValue ();
1606 if (this.defaultAttributeConsumed)
1609 defaultAttributeConsumed = true;
1614 public override string ReadInnerXml ()
1616 // MS.NET 1.0 has a serious bug here. It skips validation.
1617 return reader.ReadInnerXml ();
1620 public override string ReadOuterXml ()
1622 // MS.NET 1.0 has a serious bug here. It skips validation.
1623 return reader.ReadOuterXml ();
1627 // XmlReader.ReadString() should call derived this.Read().
1628 public override string ReadString ()
1631 return reader.ReadString ();
1633 return base.ReadString ();
1637 // This class itself does not have this feature.
1638 public override void ResolveEntity ()
1640 reader.ResolveEntity ();
1643 internal class XsdValidationContext
1645 Hashtable contextStack;
1647 public XsdValidationContext ()
1649 contextStack = new Hashtable ();
1652 // Some of them might be missing (See the spec section 5.3, and also 3.3.4).
1653 public XmlSchemaElement Element;
1654 public XsdValidationState ParticleState;
1655 public XmlSchemaAttribute [] DefaultAttributes;
1657 // Some of them might be missing (See the spec section 5.3).
1658 public object SchemaType;
1660 public object LocalTypeDefinition;
1662 public object ActualType {
1664 if (LocalTypeDefinition != null)
1665 return LocalTypeDefinition;
1671 public void Clear ()
1675 ParticleState = null;
1676 LocalTypeDefinition = null;
1679 public void PushScope (int depth)
1681 contextStack [depth] = this.MemberwiseClone ();
1684 public void PopScope (int depth)
1687 contextStack.Remove (depth + 1);
1690 public void Load (int depth)
1693 XsdValidationContext restored = (XsdValidationContext) contextStack [depth];
1694 if (restored != null) {
1695 this.Element = restored.Element;
1696 this.ParticleState = restored.ParticleState;
1697 this.SchemaType = restored.SchemaType;
1698 this.LocalTypeDefinition = restored.LocalTypeDefinition;
1704 internal class XsdValidityState
1706 ArrayList currentParticles = new ArrayList ();
1707 ArrayList occured = new ArrayList ();
1708 Hashtable xsAllConsumed = new Hashtable ();
1709 XmlSchemaParticle parciele;
1712 public XsdValidityState (XmlSchemaParticle particle)
1714 this.parciele = particle;
1715 currentParticles.Add (particle);