//<choice // id = ID // maxOccurs = (nonNegativeInteger | unbounded) : 1 // minOccurs = nonNegativeInteger : 1 // {any attributes with non-schema namespace . . .}> // Content: (annotation?, (element | group | choice | sequence | any)*) //</choice> internal static XmlSchemaChoice Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaChoice choice = new XmlSchemaChoice(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaChoice.Read, name=" + reader.Name, null); reader.SkipToEnd(); return(null); } choice.LineNumber = reader.LineNumber; choice.LinePosition = reader.LinePosition; choice.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { choice.Id = reader.Value; } else if (reader.Name == "maxOccurs") { try { choice.MaxOccursString = reader.Value; } catch (Exception e) { error(h, reader.Value + " is an invalid value for maxOccurs", e); } } else if (reader.Name == "minOccurs") { try { choice.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 choice", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, choice); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(choice); } // Content: (annotation?, (element | group | choice | sequence | any)*) int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaChoice.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) { choice.Annotation = annotation; } continue; } if (level <= 2) { if (reader.LocalName == "element") { level = 2; XmlSchemaElement element = XmlSchemaElement.Read(reader, h); if (element != null) { choice.items.Add(element); } continue; } if (reader.LocalName == "group") { level = 2; XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h); if (group != null) { choice.items.Add(group); } continue; } if (reader.LocalName == "choice") { level = 2; XmlSchemaChoice ch = XmlSchemaChoice.Read(reader, h); if (ch != null) { choice.items.Add(ch); } continue; } if (reader.LocalName == "sequence") { level = 2; XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h); if (sequence != null) { choice.items.Add(sequence); } continue; } if (reader.LocalName == "any") { level = 2; XmlSchemaAny any = XmlSchemaAny.Read(reader, h); if (any != null) { choice.items.Add(any); } continue; } } reader.RaiseInvalidElementError(); } return(choice); }
internal static XmlSchemaChoice Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaChoice xmlSchemaChoice = new XmlSchemaChoice(); reader.MoveToElement(); if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "choice") { XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaChoice.Read, name=" + reader.Name, null); reader.SkipToEnd(); return(null); } xmlSchemaChoice.LineNumber = reader.LineNumber; xmlSchemaChoice.LinePosition = reader.LinePosition; xmlSchemaChoice.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { xmlSchemaChoice.Id = reader.Value; } else if (reader.Name == "maxOccurs") { try { xmlSchemaChoice.MaxOccursString = reader.Value; } catch (Exception innerException) { XmlSchemaObject.error(h, reader.Value + " is an invalid value for maxOccurs", innerException); } } else if (reader.Name == "minOccurs") { try { xmlSchemaChoice.MinOccursString = reader.Value; } catch (Exception innerException2) { XmlSchemaObject.error(h, reader.Value + " is an invalid value for minOccurs", innerException2); } } else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema") { XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for choice", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaChoice); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(xmlSchemaChoice); } int num = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != "choice") { XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaChoice.Read, name=" + reader.Name, null); } break; } if (num <= 1 && reader.LocalName == "annotation") { num = 2; XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h); if (xmlSchemaAnnotation != null) { xmlSchemaChoice.Annotation = xmlSchemaAnnotation; } } else { if (num <= 2) { if (reader.LocalName == "element") { num = 2; XmlSchemaElement xmlSchemaElement = XmlSchemaElement.Read(reader, h); if (xmlSchemaElement != null) { xmlSchemaChoice.items.Add(xmlSchemaElement); } continue; } if (reader.LocalName == "group") { num = 2; XmlSchemaGroupRef xmlSchemaGroupRef = XmlSchemaGroupRef.Read(reader, h); if (xmlSchemaGroupRef != null) { xmlSchemaChoice.items.Add(xmlSchemaGroupRef); } continue; } if (reader.LocalName == "choice") { num = 2; XmlSchemaChoice xmlSchemaChoice2 = XmlSchemaChoice.Read(reader, h); if (xmlSchemaChoice2 != null) { xmlSchemaChoice.items.Add(xmlSchemaChoice2); } continue; } if (reader.LocalName == "sequence") { num = 2; XmlSchemaSequence xmlSchemaSequence = XmlSchemaSequence.Read(reader, h); if (xmlSchemaSequence != null) { xmlSchemaChoice.items.Add(xmlSchemaSequence); } continue; } if (reader.LocalName == "any") { num = 2; XmlSchemaAny xmlSchemaAny = XmlSchemaAny.Read(reader, h); if (xmlSchemaAny != null) { xmlSchemaChoice.items.Add(xmlSchemaAny); } continue; } } reader.RaiseInvalidElementError(); } } return(xmlSchemaChoice); }