//<simpleType // final = (#all | (list | union | restriction)) // id = ID // name = NCName // {any attributes with non-schema namespace . . .}> // Content: (annotation?, (restriction | list | union)) //</simpleType> internal static XmlSchemaSimpleType Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaSimpleType stype = new XmlSchemaSimpleType(); 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); } stype.LineNumber = reader.LineNumber; stype.LinePosition = reader.LinePosition; stype.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "final") { Exception innerex; stype.Final = XmlSchemaUtil.ReadDerivationAttribute(reader, out innerex, "final", XmlSchemaUtil.FinalAllowed); if (innerex != null) { error(h, "some invalid values not a valid value for final", innerex); } } else if (reader.Name == "id") { stype.Id = reader.Value; } else if (reader.Name == "name") { stype.Name = reader.Value; } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for simpleType", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, stype); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(stype); } // Content: (annotation?, (restriction | list | union)) int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaSimpleType.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) { stype.Annotation = annotation; } continue; } if (level <= 2) { if (reader.LocalName == "restriction") { level = 3; XmlSchemaSimpleTypeRestriction restriction = XmlSchemaSimpleTypeRestriction.Read(reader, h); if (restriction != null) { stype.content = restriction; } continue; } if (reader.LocalName == "list") { level = 3; XmlSchemaSimpleTypeList list = XmlSchemaSimpleTypeList.Read(reader, h); if (list != null) { stype.content = list; } continue; } if (reader.LocalName == "union") { level = 3; XmlSchemaSimpleTypeUnion union = XmlSchemaSimpleTypeUnion.Read(reader, h); if (union != null) { stype.content = union; } continue; } } reader.RaiseInvalidElementError(); } return(stype); }
//<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); }