//<union // id = ID // memberTypes = List of QName // {any attributes with non-schema namespace . . .}> // Content: (annotation?, (simpleType*)) //</union> internal static XmlSchemaSimpleTypeUnion Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaSimpleTypeUnion union = new XmlSchemaSimpleTypeUnion(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaSimpleTypeUnion.Read, name=" + reader.Name, null); reader.Skip(); return(null); } union.LineNumber = reader.LineNumber; union.LinePosition = reader.LinePosition; union.SourceUri = reader.BaseURI; //Read Attributes while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { union.Id = reader.Value; } else if (reader.Name == "memberTypes") { Exception innerEx; string[] names = XmlSchemaUtil.SplitList(reader.Value); union.memberTypes = new XmlQualifiedName[names.Length]; for (int i = 0; i < names.Length; i++) { union.memberTypes[i] = XmlSchemaUtil.ToQName(reader, names[i], out innerEx); if (innerEx != null) { error(h, "'" + names[i] + "' is not a valid memberType", innerEx); } } } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for union", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, union); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(union); } // Content: annotation?, simpleType* int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaSimpleTypeUnion.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) { union.Annotation = annotation; } continue; } if (level <= 2 && reader.LocalName == "simpleType") { level = 2; XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h); if (stype != null) { union.baseTypes.Add(stype); } continue; } reader.RaiseInvalidElementError(); } return(union); }
private static void ReadContent(XmlSchema schema, XmlSchemaReader reader, ValidationEventHandler h) { reader.MoveToElement(); if (reader.LocalName != "schema" && reader.NamespaceURI != XmlSchema.Namespace && reader.NodeType != XmlNodeType.Element) { error(h, "UNREACHABLE CODE REACHED: Method: Schema.ReadContent, " + reader.LocalName + ", " + reader.NamespaceURI, null); } //(include | import | redefine | annotation)*, //((simpleType | complexType | group | attributeGroup | element | attribute | notation | annotation)* int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchema.Read, name=" + reader.Name, null); } break; } if (level <= 1) { if (reader.LocalName == "include") { XmlSchemaInclude include = XmlSchemaInclude.Read(reader, h); if (include != null) { schema.includes.Add(include); } continue; } if (reader.LocalName == "import") { XmlSchemaImport import = XmlSchemaImport.Read(reader, h); if (import != null) { schema.includes.Add(import); } continue; } if (reader.LocalName == "redefine") { XmlSchemaRedefine redefine = XmlSchemaRedefine.Read(reader, h); if (redefine != null) { schema.includes.Add(redefine); } continue; } if (reader.LocalName == "annotation") { XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h); if (annotation != null) { schema.items.Add(annotation); } continue; } } if (level <= 2) { level = 2; if (reader.LocalName == "simpleType") { XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h); if (stype != null) { schema.items.Add(stype); } continue; } if (reader.LocalName == "complexType") { XmlSchemaComplexType ctype = XmlSchemaComplexType.Read(reader, h); if (ctype != null) { schema.items.Add(ctype); } continue; } if (reader.LocalName == "group") { XmlSchemaGroup group = XmlSchemaGroup.Read(reader, h); if (group != null) { schema.items.Add(group); } continue; } if (reader.LocalName == "attributeGroup") { XmlSchemaAttributeGroup attributeGroup = XmlSchemaAttributeGroup.Read(reader, h); if (attributeGroup != null) { schema.items.Add(attributeGroup); } continue; } if (reader.LocalName == "element") { XmlSchemaElement element = XmlSchemaElement.Read(reader, h); if (element != null) { schema.items.Add(element); } continue; } if (reader.LocalName == "attribute") { XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h); if (attr != null) { schema.items.Add(attr); } continue; } if (reader.LocalName == "notation") { XmlSchemaNotation notation = XmlSchemaNotation.Read(reader, h); if (notation != null) { schema.items.Add(notation); } continue; } if (reader.LocalName == "annotation") { XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h); if (annotation != null) { schema.items.Add(annotation); } continue; } } reader.RaiseInvalidElementError(); } }
//<restriction //base = QName //id = ID //{any attributes with non-schema namespace . . .}> //Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?)) //</restriction> internal static XmlSchemaSimpleContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaSimpleContentRestriction restriction = new XmlSchemaSimpleContentRestriction(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaComplexContentRestriction.Read, name=" + reader.Name, null); reader.SkipToEnd(); return(null); } restriction.LineNumber = reader.LineNumber; restriction.LinePosition = reader.LinePosition; restriction.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "base") { Exception innerex; restriction.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") { restriction.Id = reader.Value; } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for restriction", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, restriction); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(restriction); } //Content: 1.annotation?, // 2.simpleType?, // 3.(minExclusive |...| enumeration | whiteSpace | pattern)*, // 4.(attribute | attributeGroup)*, // 5.anyAttribute? int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaSimpleContentRestriction.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) { restriction.Annotation = annotation; } continue; } if (level <= 2 && reader.LocalName == "simpleType") { level = 3; XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h); if (stype != null) { restriction.baseType = stype; } continue; } if (level <= 3) { if (reader.LocalName == "minExclusive") { level = 3; XmlSchemaMinExclusiveFacet minex = XmlSchemaMinExclusiveFacet.Read(reader, h); if (minex != null) { restriction.facets.Add(minex); } continue; } else if (reader.LocalName == "minInclusive") { level = 3; XmlSchemaMinInclusiveFacet mini = XmlSchemaMinInclusiveFacet.Read(reader, h); if (mini != null) { restriction.facets.Add(mini); } continue; } else if (reader.LocalName == "maxExclusive") { level = 3; XmlSchemaMaxExclusiveFacet maxex = XmlSchemaMaxExclusiveFacet.Read(reader, h); if (maxex != null) { restriction.facets.Add(maxex); } continue; } else if (reader.LocalName == "maxInclusive") { level = 3; XmlSchemaMaxInclusiveFacet maxi = XmlSchemaMaxInclusiveFacet.Read(reader, h); if (maxi != null) { restriction.facets.Add(maxi); } continue; } else if (reader.LocalName == "totalDigits") { level = 3; XmlSchemaTotalDigitsFacet total = XmlSchemaTotalDigitsFacet.Read(reader, h); if (total != null) { restriction.facets.Add(total); } continue; } else if (reader.LocalName == "fractionDigits") { level = 3; XmlSchemaFractionDigitsFacet fraction = XmlSchemaFractionDigitsFacet.Read(reader, h); if (fraction != null) { restriction.facets.Add(fraction); } continue; } else if (reader.LocalName == "length") { level = 3; XmlSchemaLengthFacet length = XmlSchemaLengthFacet.Read(reader, h); if (length != null) { restriction.facets.Add(length); } continue; } else if (reader.LocalName == "minLength") { level = 3; XmlSchemaMinLengthFacet minlen = XmlSchemaMinLengthFacet.Read(reader, h); if (minlen != null) { restriction.facets.Add(minlen); } continue; } else if (reader.LocalName == "maxLength") { level = 3; XmlSchemaMaxLengthFacet maxlen = XmlSchemaMaxLengthFacet.Read(reader, h); if (maxlen != null) { restriction.facets.Add(maxlen); } continue; } else if (reader.LocalName == "enumeration") { level = 3; XmlSchemaEnumerationFacet enumeration = XmlSchemaEnumerationFacet.Read(reader, h); if (enumeration != null) { restriction.facets.Add(enumeration); } continue; } else if (reader.LocalName == "whiteSpace") { level = 3; XmlSchemaWhiteSpaceFacet ws = XmlSchemaWhiteSpaceFacet.Read(reader, h); if (ws != null) { restriction.facets.Add(ws); } continue; } else if (reader.LocalName == "pattern") { level = 3; XmlSchemaPatternFacet pattern = XmlSchemaPatternFacet.Read(reader, h); if (pattern != null) { restriction.facets.Add(pattern); } continue; } } if (level <= 4) { if (reader.LocalName == "attribute") { level = 4; XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h); if (attr != null) { restriction.Attributes.Add(attr); } continue; } if (reader.LocalName == "attributeGroup") { level = 4; XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h); if (attr != null) { restriction.attributes.Add(attr); } continue; } } if (level <= 5 && reader.LocalName == "anyAttribute") { level = 6; XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h); if (anyattr != null) { restriction.AnyAttribute = anyattr; } continue; } reader.RaiseInvalidElementError(); } return(restriction); }
//<redefine // id = ID // schemaLocation = anyURI // {any attributes with non-schema namespace . . .}> // Content: (annotation | (simpleType | complexType | group | attributeGroup))* //</redefine> internal static XmlSchemaRedefine Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaRedefine redefine = new XmlSchemaRedefine(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaRedefine.Read, name=" + reader.Name, null); reader.Skip(); return(null); } redefine.LineNumber = reader.LineNumber; redefine.LinePosition = reader.LinePosition; redefine.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { redefine.Id = reader.Value; } else if (reader.Name == "schemaLocation") { redefine.SchemaLocation = reader.Value; } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for redefine", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, redefine); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(redefine); } //(annotation | (simpleType | complexType | group | attributeGroup))* while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaRedefine.Read, name=" + reader.Name, null); } break; } if (reader.LocalName == "annotation") { XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h); if (annotation != null) { redefine.items.Add(annotation); } continue; } if (reader.LocalName == "simpleType") { XmlSchemaSimpleType simpleType = XmlSchemaSimpleType.Read(reader, h); if (simpleType != null) { redefine.items.Add(simpleType); } continue; } if (reader.LocalName == "complexType") { XmlSchemaComplexType complexType = XmlSchemaComplexType.Read(reader, h); if (complexType != null) { redefine.items.Add(complexType); } continue; } if (reader.LocalName == "group") { XmlSchemaGroup group = XmlSchemaGroup.Read(reader, h); if (group != null) { redefine.items.Add(group); } continue; } if (reader.LocalName == "attributeGroup") { XmlSchemaAttributeGroup attributeGroup = XmlSchemaAttributeGroup.Read(reader, h); if (attributeGroup != null) { redefine.items.Add(attributeGroup); } continue; } reader.RaiseInvalidElementError(); } return(redefine); }
//<attribute // default = string // fixed = string // form = (qualified | unqualified) // id = ID // name = NCName // ref = QName // type = QName // use = (optional | prohibited | required) : optional // {any attributes with non-schema namespace . . .}> // Content: (annotation?, (simpleType?)) //</attribute> internal static XmlSchemaAttribute Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaAttribute attribute = new XmlSchemaAttribute(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaAttribute.Read, name=" + reader.Name, null); reader.SkipToEnd(); return(null); } attribute.LineNumber = reader.LineNumber; attribute.LinePosition = reader.LinePosition; attribute.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "default") { attribute.defaultValue = reader.Value; } else if (reader.Name == "fixed") { attribute.fixedValue = reader.Value; } else if (reader.Name == "form") { Exception innerex; attribute.form = XmlSchemaUtil.ReadFormAttribute(reader, out innerex); if (innerex != null) { error(h, reader.Value + " is not a valid value for form attribute", innerex); } } else if (reader.Name == "id") { attribute.Id = reader.Value; } else if (reader.Name == "name") { attribute.name = reader.Value; } else if (reader.Name == "ref") { Exception innerex; attribute.refName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex); if (innerex != null) { error(h, reader.Value + " is not a valid value for ref attribute", innerex); } } else if (reader.Name == "type") { Exception innerex; attribute.schemaTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex); if (innerex != null) { error(h, reader.Value + " is not a valid value for type attribute", innerex); } } else if (reader.Name == "use") { Exception innerex; attribute.use = XmlSchemaUtil.ReadUseAttribute(reader, out innerex); if (innerex != null) { error(h, reader.Value + " is not a valid value for use attribute", innerex); } } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for attribute", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, attribute); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(attribute); } // Content: (annotation?, (simpleType?)) int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaAttribute.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) { attribute.Annotation = annotation; } continue; } if (level <= 2 && reader.LocalName == "simpleType") { level = 3; XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h); if (stype != null) { attribute.schemaType = stype; } continue; } reader.RaiseInvalidElementError(); } return(attribute); }
//<list // id = ID // itemType = QName // {any attributes with non-schema namespace . . .}> // Content: (annotation?, (simpleType?)) //</list> internal static XmlSchemaSimpleTypeList Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaSimpleTypeList.Read, name=" + reader.Name, null); reader.Skip(); return(null); } list.LineNumber = reader.LineNumber; list.LinePosition = reader.LinePosition; list.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { list.Id = reader.Value; } else if (reader.Name == "itemType") { Exception innerex; list.ItemTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex); if (innerex != null) { error(h, reader.Value + " is not a valid value for itemType attribute", innerex); } } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for list", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, list); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(list); } // Content: annotation?, simpleType? int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaSimpleTypeList.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) { list.Annotation = annotation; } continue; } if (level <= 2 && reader.LocalName == "simpleType") { level = 3; XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h); if (stype != null) { list.itemType = stype; } continue; } reader.RaiseInvalidElementError(); } return(list); }