internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle, ValidationEventHandler h, XmlSchema schema, bool raiseError) { XmlSchemaAny any = baseParticle as XmlSchemaAny; XmlSchemaAll derivedAll = baseParticle as XmlSchemaAll; if (any != null) { // NSRecurseCheckCardinality return(ValidateNSRecurseCheckCardinality(any, h, schema, raiseError)); } else if (derivedAll != null) { // Recurse if (!ValidateOccurenceRangeOK(derivedAll, h, schema, raiseError)) { return(false); } return(ValidateRecurse(derivedAll, h, schema, raiseError)); } else { if (raiseError) { error(h, "Invalid -all- particle derivation was found."); } return(false); } }
internal override XmlSchemaParticle GetOptimizedParticle(bool isTop) { if (OptimizedParticle != null) { return(OptimizedParticle); } if (Items.Count == 0 || ValidatedMaxOccurs == 0) { OptimizedParticle = XmlSchemaParticle.Empty; return(OptimizedParticle); } else if (Items.Count == 1) { if (ValidatedMinOccurs == 1 && ValidatedMaxOccurs == 1) { XmlSchemaSequence seq = new XmlSchemaSequence(); this.CopyInfo(seq); XmlSchemaParticle p = (XmlSchemaParticle)Items [0]; p = p.GetOptimizedParticle(false); if (p == XmlSchemaParticle.Empty) { OptimizedParticle = p; } else { seq.Items.Add(p); seq.CompiledItems.Add(p); seq.Compile(null, schema); OptimizedParticle = seq; } return(OptimizedParticle); } } XmlSchemaAll all = new XmlSchemaAll(); CopyInfo(all); CopyOptimizedItems(all); OptimizedParticle = all; all.ComputeEmptiable(); return(OptimizedParticle); }
//From the Errata //<group // id = ID // name = NCName // {any attributes with non-schema namespace . . .}> // Content: (annotation?, (all | choice | sequence)?) //</group> internal static XmlSchemaGroup Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaGroup group = new XmlSchemaGroup(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaGroup.Read, name=" + reader.Name, null); reader.Skip(); return(null); } group.LineNumber = reader.LineNumber; group.LinePosition = reader.LinePosition; group.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { group.Id = reader.Value; } else if (reader.Name == "name") { group.name = reader.Value; } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for group", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, group); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(group); } // Content: (annotation?, (all | choice | sequence)?) int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaGroup.Read, name=" + reader.Name, null); } break; } if (level <= 1 && reader.LocalName == "annotation") { level = 2; //Only one annotation XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h); if (annotation != null) { group.Annotation = annotation; } continue; } if (level <= 2) { if (reader.LocalName == "all") { level = 3; XmlSchemaAll all = XmlSchemaAll.Read(reader, h); if (all != null) { group.Particle = all; } continue; } if (reader.LocalName == "choice") { level = 3; XmlSchemaChoice choice = XmlSchemaChoice.Read(reader, h); if (choice != null) { group.Particle = choice; } continue; } if (reader.LocalName == "sequence") { level = 3; XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h); if (sequence != null) { group.Particle = sequence; } continue; } } reader.RaiseInvalidElementError(); } return(group); }
//<extension // base = QName // id = ID // {any attributes with non-schema namespace . . .}> // Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))) //</extension> internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null); reader.Skip(); return(null); } extension.LineNumber = reader.LineNumber; extension.LinePosition = reader.LinePosition; extension.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "base") { Exception innerex; extension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex); if (innerex != null) { error(h, reader.Value + " is not a valid value for base attribute", innerex); } } else if (reader.Name == "id") { extension.Id = reader.Value; } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for extension", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, extension); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(extension); } //Content: 1. annotation?, // (2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?))) int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null); } break; } if (level <= 1 && reader.LocalName == "annotation") { level = 2; //Only one annotation XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h); if (annotation != null) { extension.Annotation = annotation; } continue; } if (level <= 2) { if (reader.LocalName == "group") { level = 3; XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h); if (group != null) { extension.particle = group; } continue; } if (reader.LocalName == "all") { level = 3; XmlSchemaAll all = XmlSchemaAll.Read(reader, h); if (all != null) { extension.particle = all; } continue; } if (reader.LocalName == "choice") { level = 3; XmlSchemaChoice choice = XmlSchemaChoice.Read(reader, h); if (choice != null) { extension.particle = choice; } continue; } if (reader.LocalName == "sequence") { level = 3; XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h); if (sequence != null) { extension.particle = sequence; } continue; } } if (level <= 3) { if (reader.LocalName == "attribute") { level = 3; XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h); if (attr != null) { extension.Attributes.Add(attr); } continue; } if (reader.LocalName == "attributeGroup") { level = 3; XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h); if (attr != null) { extension.attributes.Add(attr); } continue; } } if (level <= 4 && reader.LocalName == "anyAttribute") { level = 5; XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h); if (anyattr != null) { extension.AnyAttribute = anyattr; } continue; } reader.RaiseInvalidElementError(); } return(extension); }
//<all // id = ID // maxOccurs = 1 : 1 // minOccurs = (0 | 1) : 1 // {any attributes with non-schema namespace . . .}> // Content: (annotation?, element*) //</all> internal static XmlSchemaAll Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaAll all = new XmlSchemaAll(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaAll.Read, name=" + reader.Name, null); reader.SkipToEnd(); return(null); } all.LineNumber = reader.LineNumber; all.LinePosition = reader.LinePosition; all.SourceUri = reader.BaseURI; //Read Attributes while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { all.Id = reader.Value; } else if (reader.Name == "maxOccurs") { try { all.MaxOccursString = reader.Value; } catch (Exception e) { error(h, reader.Value + " is an invalid value for maxOccurs", e); } } else if (reader.Name == "minOccurs") { try { all.MinOccursString = reader.Value; } catch (Exception e) { error(h, reader.Value + " is an invalid value for minOccurs", e); } } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for all", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, all); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(all); } //Content: (annotation?, element*) int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaAll.Read, name=" + reader.Name, null); } break; } if (level <= 1 && reader.LocalName == "annotation") { level = 2; //Only one annotation XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h); if (annotation != null) { all.Annotation = annotation; } continue; } if (level <= 2 && reader.LocalName == "element") { level = 2; XmlSchemaElement element = XmlSchemaElement.Read(reader, h); if (element != null) { all.items.Add(element); } continue; } reader.RaiseInvalidElementError(); } return(all); }
internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle, ValidationEventHandler h, XmlSchema schema, bool raiseError) { if (this == baseParticle) // quick check { return(true); } XmlSchemaElement el = baseParticle as XmlSchemaElement; if (el != null) { // Forbidden if (raiseError) { error(h, "Invalid sequence paricle derivation."); } return(false); } XmlSchemaSequence seq = baseParticle as XmlSchemaSequence; if (seq != null) { // Recurse if (!ValidateOccurenceRangeOK(seq, h, schema, raiseError)) { return(false); } // If it is totally optional, then ignore their contents. if (seq.ValidatedMinOccurs == 0 && seq.ValidatedMaxOccurs == 0 && this.ValidatedMinOccurs == 0 && this.ValidatedMaxOccurs == 0) { return(true); } return(ValidateRecurse(seq, h, schema, raiseError)); } XmlSchemaAll all = baseParticle as XmlSchemaAll; if (all != null) { // RecurseUnordered XmlSchemaObjectCollection already = new XmlSchemaObjectCollection(); for (int i = 0; i < this.Items.Count; i++) { XmlSchemaElement de = this.Items [i] as XmlSchemaElement; if (de == null) { if (raiseError) { error(h, "Invalid sequence particle derivation by restriction from all."); } return(false); } foreach (XmlSchemaElement e in all.Items) { if (e.QualifiedName == de.QualifiedName) { if (already.Contains(e)) { if (raiseError) { error(h, "Base element particle is mapped to the derived element particle in a sequence two or more times."); } return(false); } else { already.Add(e); if (!de.ValidateDerivationByRestriction(e, h, schema, raiseError)) { return(false); } } } } } foreach (XmlSchemaElement e in all.Items) { if (!already.Contains(e)) { if (!e.ValidateIsEmptiable()) { if (raiseError) { error(h, "In base -all- particle, mapping-skipped base element which is not emptiable was found."); } return(false); } } } return(true); } XmlSchemaAny any = baseParticle as XmlSchemaAny; if (any != null) { // NSRecurseCheckCardinality return(ValidateNSRecurseCheckCardinality(any, h, schema, raiseError)); } XmlSchemaChoice choice = baseParticle as XmlSchemaChoice; if (choice != null) { // MapAndSum // In fact it is not Recurse, but it looks almost common. return(ValidateSeqRecurseMapSumCommon(choice, h, schema, false, true, raiseError)); } return(true); }