internal static XmlSchemaParticle CloneParticle(XmlSchemaParticle particle) { XmlSchemaGroupBase groupBase = particle as XmlSchemaGroupBase; if (groupBase != null && !(groupBase is XmlSchemaAll)) //Choice or sequence { XmlSchemaGroupBase newGroupBase = groupBase; XmlSchemaObjectCollection newGroupbaseParticles = CloneGroupBaseParticles(groupBase.Items); newGroupBase = (XmlSchemaGroupBase)groupBase.Clone(); newGroupBase.SetItems(newGroupbaseParticles); return(newGroupBase); } else if (particle is XmlSchemaGroupRef) // group ref { XmlSchemaGroupRef newGroupRef = (XmlSchemaGroupRef)particle.Clone(); newGroupRef.RefName = newGroupRef.RefName.Clone(); return(newGroupRef); } else { XmlSchemaElement oldElem = particle as XmlSchemaElement; if (oldElem != null && (!oldElem.RefName.IsEmpty || !oldElem.SchemaTypeName.IsEmpty)) //Its element ref or type name is present { XmlSchemaElement newElem = (XmlSchemaElement)oldElem.Clone(); return(newElem); } } return(particle); }
public static XmlSchemaGroup ResolveGroup(this XmlSchemaSet schemaSet, XmlSchemaGroupRef groupRef) { foreach (var schema in schemaSet.GetAllSchemas()) { var group = (XmlSchemaGroup)schema.Groups[groupRef.RefName]; if (group != null) return group; } return null; }
internal static XmlSchemaParticle?CloneParticle(XmlSchemaParticle?particle, XmlSchema?parentSchema) { XmlSchemaGroupBase?groupBase = particle as XmlSchemaGroupBase; if (groupBase != null) { //Choice or sequence XmlSchemaGroupBase newGroupBase; XmlSchemaObjectCollection newGroupbaseParticles = CloneGroupBaseParticles(groupBase.Items, parentSchema); newGroupBase = (XmlSchemaGroupBase)groupBase.Clone(); newGroupBase.SetItems(newGroupbaseParticles); return(newGroupBase); } else if (particle is XmlSchemaGroupRef) { // group ref XmlSchemaGroupRef newGroupRef = (XmlSchemaGroupRef)particle.Clone(); newGroupRef.RefName = newGroupRef.RefName.Clone(); return(newGroupRef); } else { XmlSchemaElement?oldElem = particle as XmlSchemaElement; // If the particle is an element and one of the following is true: // - it references another element by name // - it references its type by name // - it's form (effective) is qualified (meaning it will inherint namespace from chameleon includes if that happens) // then the element itself needs to be cloned. if (oldElem != null && (!oldElem.RefName.IsEmpty || !oldElem.SchemaTypeName.IsEmpty || GetResolvedElementForm(parentSchema, oldElem) == XmlSchemaForm.Qualified)) { XmlSchemaElement newElem = (XmlSchemaElement)oldElem.Clone(parentSchema); return(newElem); } } return(particle); }
internal static XmlSchemaParticle CloneParticle(XmlSchemaParticle particle, XmlSchema parentSchema) { XmlSchemaGroupBase base2 = particle as XmlSchemaGroupBase; if (base2 != null) { XmlSchemaGroupBase base3 = base2; XmlSchemaObjectCollection newItems = CloneGroupBaseParticles(base2.Items, parentSchema); base3 = (XmlSchemaGroupBase) base2.Clone(); base3.SetItems(newItems); return base3; } if (particle is XmlSchemaGroupRef) { XmlSchemaGroupRef ref2 = (XmlSchemaGroupRef) particle.Clone(); ref2.RefName = ref2.RefName.Clone(); return ref2; } XmlSchemaElement element = particle as XmlSchemaElement; if ((element == null) || ((element.RefName.IsEmpty && element.SchemaTypeName.IsEmpty) && (GetResolvedElementForm(parentSchema, element) != XmlSchemaForm.Qualified))) { return particle; } return (XmlSchemaElement) element.Clone(parentSchema); }
XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup) { XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup)); return grp.Particle; }
private XmlSchemaParticle CannonicalizeGroupRef(XmlSchemaGroupRef groupRef, bool root) { XmlSchemaGroup group; if (groupRef.Redefined != null) { group = groupRef.Redefined; } else { group = (XmlSchemaGroup)groups[groupRef.RefName]; } if (group == null) { SendValidationEvent(Res.Sch_UndefGroupRef, groupRef.RefName.ToString(), groupRef); return XmlSchemaParticle.Empty; } if (group.CanonicalParticle == null) { CompileGroup(group); } if (group.CanonicalParticle == XmlSchemaParticle.Empty) { return XmlSchemaParticle.Empty; } XmlSchemaGroupBase groupBase = (XmlSchemaGroupBase)group.CanonicalParticle; if (groupBase is XmlSchemaAll) { if (!root) { SendValidationEvent(Res.Sch_AllRefNotRoot, "", groupRef); return XmlSchemaParticle.Empty; } if (groupRef.MinOccurs > decimal.One || groupRef.MaxOccurs != decimal.One) { SendValidationEvent(Res.Sch_AllRefMinMax, groupRef); return XmlSchemaParticle.Empty; } } else if (groupBase is XmlSchemaChoice && groupBase.Items.Count == 0) { if (groupRef.MinOccurs != decimal.Zero) { SendValidationEvent(Res.Sch_EmptyChoice, groupRef, XmlSeverityType.Warning); } return XmlSchemaParticle.Empty; } XmlSchemaGroupBase groupRefBase = ( (groupBase is XmlSchemaSequence) ? (XmlSchemaGroupBase)new XmlSchemaSequence() : (groupBase is XmlSchemaChoice) ? (XmlSchemaGroupBase)new XmlSchemaChoice() : (XmlSchemaGroupBase)new XmlSchemaAll() ); groupRefBase.MinOccurs = groupRef.MinOccurs; groupRefBase.MaxOccurs = groupRef.MaxOccurs; CopyPosition(groupRefBase, groupRef, true); for (int i = 0; i < groupBase.Items.Count; ++i) { groupRefBase.Items.Add(groupBase.Items[i]); } groupRef.SetParticle(groupRefBase); return groupRefBase; }
XmlSchemaElement FindElement(XmlSchemaGroupRef groupRef, QualifiedName name) { XmlSchemaGroup schemaGroup = FindGroup(groupRef.RefName.Name); if (schemaGroup != null) { XmlSchemaSequence sequence = schemaGroup.Particle as XmlSchemaSequence; XmlSchemaChoice choice = schemaGroup.Particle as XmlSchemaChoice; if(sequence != null) { return FindElement(sequence.Items, name); } else if (choice != null) { return FindElement(choice.Items, name); } } return null; }
XmlSchemaElement FindElement (XmlSchemaGroupRef groupRef, QualifiedName name) { var group = FindGroup (groupRef.RefName.Name); if (group == null) return null; var sequence = group.Particle as XmlSchemaSequence; if (sequence != null) return FindElement (sequence.Items, name); var choice = group.Particle as XmlSchemaChoice; if (choice != null) return FindElement (choice.Items, name); return null; }
protected override void Visit(XmlSchemaGroupRef groupRef) { // Don't visit children. }
protected override void Visit(XmlSchemaGroupRef groupRef) { if (groupRef.MaxOccurs == 0) return; var group = _schemaSetManager.SchemaSet.ResolveGroup(groupRef); Traverse(group.Particle); }
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); }
private static XmlSchema CreateFakeSoapEncodingSchema(string ns, string name) { XmlSchema schema = new XmlSchema(); schema.TargetNamespace = ns; XmlSchemaGroup item = new XmlSchemaGroup(); item.Name = "Array"; XmlSchemaSequence sequence = new XmlSchemaSequence(); XmlSchemaAny any = new XmlSchemaAny(); any.MinOccurs = 0M; any.MaxOccurs = 79228162514264337593543950335M; sequence.Items.Add(any); any.Namespace = "##any"; any.ProcessContents = XmlSchemaContentProcessing.Lax; item.Particle = sequence; schema.Items.Add(item); XmlSchemaComplexType type = new XmlSchemaComplexType(); type.Name = name; XmlSchemaGroupRef ref2 = new XmlSchemaGroupRef(); ref2.RefName = new XmlQualifiedName("Array", ns); type.Particle = ref2; XmlSchemaAttribute attribute = new XmlSchemaAttribute(); attribute.RefName = new XmlQualifiedName("arrayType", ns); type.Attributes.Add(attribute); schema.Items.Add(type); attribute = new XmlSchemaAttribute(); attribute.Use = XmlSchemaUse.None; attribute.Name = "arrayType"; schema.Items.Add(attribute); AddSimpleType(schema, "base64", "base64Binary"); AddElementAndType(schema, "anyURI", ns); AddElementAndType(schema, "base64Binary", ns); AddElementAndType(schema, "boolean", ns); AddElementAndType(schema, "byte", ns); AddElementAndType(schema, "date", ns); AddElementAndType(schema, "dateTime", ns); AddElementAndType(schema, "decimal", ns); AddElementAndType(schema, "double", ns); AddElementAndType(schema, "duration", ns); AddElementAndType(schema, "ENTITIES", ns); AddElementAndType(schema, "ENTITY", ns); AddElementAndType(schema, "float", ns); AddElementAndType(schema, "gDay", ns); AddElementAndType(schema, "gMonth", ns); AddElementAndType(schema, "gMonthDay", ns); AddElementAndType(schema, "gYear", ns); AddElementAndType(schema, "gYearMonth", ns); AddElementAndType(schema, "hexBinary", ns); AddElementAndType(schema, "ID", ns); AddElementAndType(schema, "IDREF", ns); AddElementAndType(schema, "IDREFS", ns); AddElementAndType(schema, "int", ns); AddElementAndType(schema, "integer", ns); AddElementAndType(schema, "language", ns); AddElementAndType(schema, "long", ns); AddElementAndType(schema, "Name", ns); AddElementAndType(schema, "NCName", ns); AddElementAndType(schema, "negativeInteger", ns); AddElementAndType(schema, "NMTOKEN", ns); AddElementAndType(schema, "NMTOKENS", ns); AddElementAndType(schema, "nonNegativeInteger", ns); AddElementAndType(schema, "nonPositiveInteger", ns); AddElementAndType(schema, "normalizedString", ns); AddElementAndType(schema, "positiveInteger", ns); AddElementAndType(schema, "QName", ns); AddElementAndType(schema, "short", ns); AddElementAndType(schema, "string", ns); AddElementAndType(schema, "time", ns); AddElementAndType(schema, "token", ns); AddElementAndType(schema, "unsignedByte", ns); AddElementAndType(schema, "unsignedInt", ns); AddElementAndType(schema, "unsignedLong", ns); AddElementAndType(schema, "unsignedShort", ns); return schema; }
private static XmlSchema CreateFakeSoapEncodingSchema(string ns, string name) { XmlSchema schema1 = new XmlSchema(); schema1.TargetNamespace = ns; XmlSchemaGroup group1 = new XmlSchemaGroup(); group1.Name = "Array"; XmlSchemaSequence sequence1 = new XmlSchemaSequence(); XmlSchemaAny any1 = new XmlSchemaAny(); any1.MinOccurs = new decimal(0); any1.MaxOccurs = new decimal(-1, -1, -1, false, 0); sequence1.Items.Add(any1); any1.Namespace = "##any"; any1.ProcessContents = XmlSchemaContentProcessing.Lax; group1.Particle = sequence1; schema1.Items.Add(group1); XmlSchemaComplexType type1 = new XmlSchemaComplexType(); type1.Name = name; XmlSchemaGroupRef ref1 = new XmlSchemaGroupRef(); ref1.RefName = new XmlQualifiedName("Array", ns); type1.Particle = ref1; XmlSchemaAttribute attribute1 = new XmlSchemaAttribute(); attribute1.RefName = new XmlQualifiedName("arrayType", ns); type1.Attributes.Add(attribute1); schema1.Items.Add(type1); attribute1 = new XmlSchemaAttribute(); attribute1.Use = XmlSchemaUse.None; attribute1.Name = "arrayType"; schema1.Items.Add(attribute1); AddSimpleType(schema1, "base64", "base64Binary"); AddElementAndType(schema1, "anyURI", ns); AddElementAndType(schema1, "base64Binary", ns); AddElementAndType(schema1, "boolean", ns); AddElementAndType(schema1, "byte", ns); AddElementAndType(schema1, "date", ns); AddElementAndType(schema1, "dateTime", ns); AddElementAndType(schema1, "decimal", ns); AddElementAndType(schema1, "double", ns); AddElementAndType(schema1, "duration", ns); AddElementAndType(schema1, "ENTITIES", ns); AddElementAndType(schema1, "ENTITY", ns); AddElementAndType(schema1, "float", ns); AddElementAndType(schema1, "gDay", ns); AddElementAndType(schema1, "gMonth", ns); AddElementAndType(schema1, "gMonthDay", ns); AddElementAndType(schema1, "gYear", ns); AddElementAndType(schema1, "gYearMonth", ns); AddElementAndType(schema1, "hexBinary", ns); AddElementAndType(schema1, "ID", ns); AddElementAndType(schema1, "IDREF", ns); AddElementAndType(schema1, "IDREFS", ns); AddElementAndType(schema1, "int", ns); AddElementAndType(schema1, "integer", ns); AddElementAndType(schema1, "language", ns); AddElementAndType(schema1, "long", ns); AddElementAndType(schema1, "Name", ns); AddElementAndType(schema1, "NCName", ns); AddElementAndType(schema1, "negativeInteger", ns); AddElementAndType(schema1, "NMTOKEN", ns); AddElementAndType(schema1, "NMTOKENS", ns); AddElementAndType(schema1, "nonNegativeInteger", ns); AddElementAndType(schema1, "nonPositiveInteger", ns); AddElementAndType(schema1, "normalizedString", ns); AddElementAndType(schema1, "positiveInteger", ns); AddElementAndType(schema1, "QName", ns); AddElementAndType(schema1, "short", ns); AddElementAndType(schema1, "string", ns); AddElementAndType(schema1, "time", ns); AddElementAndType(schema1, "token", ns); AddElementAndType(schema1, "unsignedByte", ns); AddElementAndType(schema1, "unsignedInt", ns); AddElementAndType(schema1, "unsignedLong", ns); AddElementAndType(schema1, "unsignedShort", ns); return schema1; }
private void Write44_XmlSchemaGroupRef(string n, string ns, XmlSchemaGroupRef o, bool isNullable, bool needType) { if (o == null) { if (isNullable) { base.WriteNullTagLiteral(n, ns); } } else { if (!needType && !(o.GetType() == typeof(XmlSchemaGroupRef))) { throw base.CreateUnknownTypeException(o); } base.EscapeName = false; base.WriteStartElement(n, ns, o, false, o.Namespaces); if (needType) { base.WriteXsiType("XmlSchemaGroupRef", "http://www.w3.org/2001/XMLSchema"); } base.WriteAttribute("id", "", o.Id); XmlAttribute[] unhandledAttributes = o.UnhandledAttributes; if (unhandledAttributes != null) { for (int i = 0; i < unhandledAttributes.Length; i++) { XmlAttribute node = unhandledAttributes[i]; base.WriteXmlAttribute(node, o); } } base.WriteAttribute("minOccurs", "", o.MinOccursString); base.WriteAttribute("maxOccurs", "", o.MaxOccursString); base.WriteAttribute("ref", "", base.FromXmlQualifiedName(o.RefName)); this.Write11_XmlSchemaAnnotation("annotation", "http://www.w3.org/2001/XMLSchema", o.Annotation, false, false); base.WriteEndElement(o); } }
// <group // id = ID // ref = QName // minOccurs = ? : 1 // maxOccurs = ? : 1> // Content: (annotation?) // </group> internal static XmlSchemaGroupRef Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaGroupRef groupref = new XmlSchemaGroupRef(); 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; } groupref.LineNumber = reader.LineNumber; groupref.LinePosition = reader.LinePosition; groupref.SourceUri = reader.BaseURI; while(reader.MoveToNextAttribute()) { if(reader.Name == "id") { groupref.Id = reader.Value; } else if(reader.Name == "ref") { Exception innerex; groupref.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 == "maxOccurs") { try { groupref.MaxOccursString = reader.Value; } catch(Exception e) { error(h,reader.Value + " is an invalid value for maxOccurs",e); } } else if(reader.Name == "minOccurs") { try { groupref.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 group",null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader,groupref); } } reader.MoveToElement(); if(reader.IsEmptyElement) return groupref; // Content: (annotation?) int level = 1; while(reader.ReadNextElement()) { if(reader.NodeType == XmlNodeType.EndElement) { if(reader.LocalName != xmlname) error(h,"Should not happen :2: XmlSchemaGroupRef.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) groupref.Annotation = annotation; continue; } reader.RaiseInvalidElementError(); } return groupref; }
void Write55_XmlSchemaGroupRef(XmlSchemaGroupRef o) { if ((object)o == null) return; WriteStartElement("group"); WriteAttribute(@"id", @"", ((System.String)o.@Id)); WriteAttribute("minOccurs", "", XmlConvert.ToString(o.MinOccurs)); WriteAttribute(@"maxOccurs", @"", o.MaxOccurs == decimal.MaxValue ? "unbounded" : XmlConvert.ToString(o.MaxOccurs)); if (!o.RefName.IsEmpty) { WriteAttribute("ref", "", o.RefName); } WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o); Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation); WriteEndElement(); }
protected virtual void Visit(XmlSchemaGroupRef groupRef) { }
//<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); }
private void Write55_XmlSchemaGroupRef(XmlSchemaGroupRef o) { if (o != null) { this.WriteStartElement("group"); this.WriteAttribute("id", "", o.Id); this.WriteAttribute("minOccurs", "", XmlConvert.ToString(o.MinOccurs)); this.WriteAttribute("maxOccurs", "", (o.MaxOccurs == 79228162514264337593543950335M) ? "unbounded" : XmlConvert.ToString(o.MaxOccurs)); if (!o.RefName.IsEmpty) { this.WriteAttribute("ref", "", o.RefName); } this.WriteAttributes(o.UnhandledAttributes, o); this.Write5_XmlSchemaAnnotation(o.Annotation); this.WriteEndElement(); } }
void GetChildElementCompletionData (XmlCompletionDataList data, XmlSchemaGroupRef groupRef, string prefix) { var group = FindGroup (groupRef.RefName.Name); if (group == null) return; var sequence = group.Particle as XmlSchemaSequence; if (sequence != null) { GetChildElementCompletionData (data, sequence.Items, prefix); return; } var choice = group.Particle as XmlSchemaChoice; if (choice != null) { GetChildElementCompletionData (data, choice.Items, prefix); return; } }
/// <summary> /// Convert the property into a schema object /// </summary> public override void GenerateSchemaTypeObjects(PropertyInfo property, XmlSchemaType type, int level) { Debug.IndentLevel = level; Debug.WriteLine("Default {0} {1} {2}", level, property.Name, type.Name); var configPropertyAtts = GetAttributes<ConfigurationPropertyAttribute>(property); if (configPropertyAtts.Length == 0) return; var element = new XmlSchemaElement(); var firstConfigPropertyAttribute = configPropertyAtts[0]; element.Name = firstConfigPropertyAttribute.Name; if (!firstConfigPropertyAttribute.IsRequired) { element.MinOccurs = 0; } var ct = new XmlSchemaComplexType(); element.SchemaType = ct; var configCollPropertyAtts = GetAttributes<ConfigurationCollectionAttribute>(property); if (configCollPropertyAtts.Length == 0) configCollPropertyAtts = GetAttributes<ConfigurationCollectionAttribute>(property.PropertyType); if (configCollPropertyAtts.Length == 0) return; var configCollAttribute = configCollPropertyAtts[0]; // we are actually going to add the collection to the parent type by creating // a new group type that consists of a sequence of all the elements that we // expect in the collection var name = property.DeclaringType.FullName + "." + property.PropertyType.Name; name = name.Replace("+", "_"); var groupParticle = XmlHelper.CreateGroupType(name); XmlSchemaGroupBase seq; if (XmlHelper.UseAll && (configCollAttribute.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMap || configCollAttribute.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate)) seq = new XmlSchemaAll(); else seq = new XmlSchemaSequence(); groupParticle.Particle = seq; // add support for the child elements AddCollectionChildren(groupParticle.Particle, configCollAttribute, level); // now add the group to the schema and the parent CT if (Generator.Schema.Items.OfType<XmlSchemaGroup>().All(x => x.Name != groupParticle.Name)) Generator.Schema.Items.Add(groupParticle); var parentCt = (XmlSchemaComplexType) type; var groupRef = new XmlSchemaGroupRef { RefName = new XmlQualifiedName(XmlHelper.PrependNamespaceAlias(groupParticle.Name)) }; ct.Particle = groupRef; var items = ((XmlSchemaGroupBase) parentCt.Particle).Items; if (items.OfType<XmlSchemaElement>().All(x => x.Name != element.Name)) items.Add(element); /* if (items.OfType<XmlSchemaGroupRef>().All(x => x.RefName != groupRef.RefName)) items.Add(groupRef);*/ // add the documentation groupRef.AddAnnotation(property, firstConfigPropertyAttribute); }
private static XmlSchema CreateFakeSoapEncodingSchema(string ns, string name) { // Create soap encoding schema XmlSchema schema = new XmlSchema(); schema.TargetNamespace = ns; // Add Array type: /* <xs:group name="Array"> <xs:sequence> <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" /> </xs:sequence> </xs:group> <xs:element name="Array" type="tns:Array" /> <xs:complexType name="Array"> <xs:group minOccurs="0" ref="tns:Array" /> </xs:complexType> */ XmlSchemaGroup group = new XmlSchemaGroup(); group.Name = "Array"; XmlSchemaSequence seq = new XmlSchemaSequence(); XmlSchemaAny any = new XmlSchemaAny(); any.MinOccurs = 0; any.MaxOccurs = decimal.MaxValue; seq.Items.Add(any); any.Namespace = "##any"; any.ProcessContents = XmlSchemaContentProcessing.Lax; group.Particle = seq; schema.Items.Add(group); XmlSchemaComplexType type = new XmlSchemaComplexType(); type.Name = name; XmlSchemaGroupRef qroupRef = new XmlSchemaGroupRef(); qroupRef.RefName = new XmlQualifiedName("Array", ns); type.Particle = qroupRef; XmlSchemaAttribute attribute = new XmlSchemaAttribute(); attribute.RefName = new XmlQualifiedName("arrayType", ns); type.Attributes.Add(attribute); schema.Items.Add(type); attribute = new XmlSchemaAttribute(); attribute.Use = XmlSchemaUse.None; attribute.Name = "arrayType"; schema.Items.Add(attribute); AddSimpleType(schema, "base64", "base64Binary"); // Add all types derived from the primitive XSD types AddElementAndType(schema, "anyURI", ns); AddElementAndType(schema, "base64Binary", ns); AddElementAndType(schema, "boolean", ns); AddElementAndType(schema, "byte", ns); AddElementAndType(schema, "date", ns); AddElementAndType(schema, "dateTime", ns); AddElementAndType(schema, "decimal", ns); AddElementAndType(schema, "double", ns); AddElementAndType(schema, "duration", ns); AddElementAndType(schema, "ENTITIES", ns); AddElementAndType(schema, "ENTITY", ns); AddElementAndType(schema, "float", ns); AddElementAndType(schema, "gDay", ns); AddElementAndType(schema, "gMonth", ns); AddElementAndType(schema, "gMonthDay", ns); AddElementAndType(schema, "gYear", ns); AddElementAndType(schema, "gYearMonth", ns); AddElementAndType(schema, "hexBinary", ns); AddElementAndType(schema, "ID", ns); AddElementAndType(schema, "IDREF", ns); AddElementAndType(schema, "IDREFS", ns); AddElementAndType(schema, "int", ns); AddElementAndType(schema, "integer", ns); AddElementAndType(schema, "language", ns); AddElementAndType(schema, "long", ns); AddElementAndType(schema, "Name", ns); AddElementAndType(schema, "NCName", ns); AddElementAndType(schema, "negativeInteger", ns); AddElementAndType(schema, "NMTOKEN", ns); AddElementAndType(schema, "NMTOKENS", ns); AddElementAndType(schema, "nonNegativeInteger", ns); AddElementAndType(schema, "nonPositiveInteger", ns); AddElementAndType(schema, "normalizedString", ns); AddElementAndType(schema, "positiveInteger", ns); AddElementAndType(schema, "QName", ns); AddElementAndType(schema, "short", ns); AddElementAndType(schema, "string", ns); AddElementAndType(schema, "time", ns); AddElementAndType(schema, "token", ns); AddElementAndType(schema, "unsignedByte", ns); AddElementAndType(schema, "unsignedInt", ns); AddElementAndType(schema, "unsignedLong", ns); AddElementAndType(schema, "unsignedShort", ns); return schema; }
/// <summary> /// Returns an XmlSchema for the TimeChnageType that describes the /// XML representation of the output that is produced by the WriteXml /// method and consumed by the ReadXmlMethod /// </summary> /// <returns>XmlSchema for the TimeChangeType</returns> public System.Xml.Schema.XmlSchema GetSchema() { // This method must return //<xs:schema // id="types" // elementFormDefault="qualified" // version="Exchange2007" // xmlns:t="http://…/types" // targetNamespace="http://…/types" // xmlns:tns="http://…/types" // xmlns:xs="http://www.w3.org/2001/XMLSchema"> // <xs:complexType name="TimeChangeType"> // <xs:sequence> // <xs:element name="Offset" type="xs:duration" /> // <xs:group ref="t:TimeChangePatternTypes" minOccurs="0"/> // <xs:element name="Time" type="xs:time" /> // </xs:sequence> // <xs:attribute name="TimeZoneName" // type="xs:string" use="optional" /> //</xs:complexType> //</xs:schema> string xsTypes = "http://schemas.microsoft.com/exchange/services/2006/types"; string xsSchema = "http://www.w3.org/2001/XMLSchema"; XmlSchema schema = new XmlSchema(); schema.Id = "types"; schema.ElementFormDefault = XmlSchemaForm.Qualified; schema.Version = "Exchange2007"; schema.TargetNamespace = xsTypes; // <xs:complexType … > XmlSchemaComplexType xmlct1 = new XmlSchemaComplexType(); schema.Items.Add(xmlct1); xmlct1.Name = "TimeChangeType"; // <xs:sequence … > XmlSchemaSequence xmlsq1 = new XmlSchemaSequence(); xmlct1.Particle = xmlsq1; // <xs:element … /> XmlSchemaElement xmle1 = new XmlSchemaElement(); xmlsq1.Items.Add(xmle1); xmle1.Name = "Offset"; xmle1.SchemaTypeName = new XmlQualifiedName("duration", xsSchema); // <xs:group … /> XmlSchemaGroupRef xmlgr1 = new XmlSchemaGroupRef(); xmlsq1.Items.Add(xmlgr1); xmlgr1.RefName = new XmlQualifiedName("TimeChangePatternTypes", xsTypes); xmlgr1.MinOccurs = 0; // <xs:element … /> XmlSchemaElement xmle2 = new XmlSchemaElement(); xmlsq1.Items.Add(xmle2); xmle2.Name = "Time"; xmle2.SchemaTypeName = new XmlQualifiedName("time", xsSchema); // <xs:attribute … /> XmlSchemaAttribute xmla1 = new XmlSchemaAttribute(); xmlct1.Attributes.Add(xmla1); xmla1.Name = "TimeZoneName"; xmla1.Use = XmlSchemaUse.Optional; xmla1.SchemaTypeName = new XmlQualifiedName("string", xsSchema); return schema; }
XmlCompletionItemCollection GetChildElementCompletion(XmlSchemaGroupRef groupRef, string prefix) { XmlSchemaGroup schemaGroup = FindGroup(groupRef.RefName.Name); if (schemaGroup != null) { XmlSchemaSequence sequence = schemaGroup.Particle as XmlSchemaSequence; XmlSchemaChoice choice = schemaGroup.Particle as XmlSchemaChoice; if(sequence != null) { return GetChildElementCompletion(sequence.Items, prefix); } else if (choice != null) { return GetChildElementCompletion(choice.Items, prefix); } } return new XmlCompletionItemCollection(); }
public virtual void Check (ConformanceCheckContext ctx, XmlSchemaGroupRef value) {}
internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaComplexContentExtension xmlSchemaComplexContentExtension = new XmlSchemaComplexContentExtension(); reader.MoveToElement(); if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "extension") { XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null); reader.Skip(); return(null); } xmlSchemaComplexContentExtension.LineNumber = reader.LineNumber; xmlSchemaComplexContentExtension.LinePosition = reader.LinePosition; xmlSchemaComplexContentExtension.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "base") { Exception ex; xmlSchemaComplexContentExtension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out ex); if (ex != null) { XmlSchemaObject.error(h, reader.Value + " is not a valid value for base attribute", ex); } } else if (reader.Name == "id") { xmlSchemaComplexContentExtension.Id = reader.Value; } 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 extension", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaComplexContentExtension); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(xmlSchemaComplexContentExtension); } int num = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != "extension") { XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null); } break; } if (num <= 1 && reader.LocalName == "annotation") { num = 2; XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h); if (xmlSchemaAnnotation != null) { xmlSchemaComplexContentExtension.Annotation = xmlSchemaAnnotation; } } else { if (num <= 2) { if (reader.LocalName == "group") { num = 3; XmlSchemaGroupRef xmlSchemaGroupRef = XmlSchemaGroupRef.Read(reader, h); if (xmlSchemaGroupRef != null) { xmlSchemaComplexContentExtension.particle = xmlSchemaGroupRef; } continue; } if (reader.LocalName == "all") { num = 3; XmlSchemaAll xmlSchemaAll = XmlSchemaAll.Read(reader, h); if (xmlSchemaAll != null) { xmlSchemaComplexContentExtension.particle = xmlSchemaAll; } continue; } if (reader.LocalName == "choice") { num = 3; XmlSchemaChoice xmlSchemaChoice = XmlSchemaChoice.Read(reader, h); if (xmlSchemaChoice != null) { xmlSchemaComplexContentExtension.particle = xmlSchemaChoice; } continue; } if (reader.LocalName == "sequence") { num = 3; XmlSchemaSequence xmlSchemaSequence = XmlSchemaSequence.Read(reader, h); if (xmlSchemaSequence != null) { xmlSchemaComplexContentExtension.particle = xmlSchemaSequence; } continue; } } if (num <= 3) { if (reader.LocalName == "attribute") { num = 3; XmlSchemaAttribute xmlSchemaAttribute = XmlSchemaAttribute.Read(reader, h); if (xmlSchemaAttribute != null) { xmlSchemaComplexContentExtension.Attributes.Add(xmlSchemaAttribute); } continue; } if (reader.LocalName == "attributeGroup") { num = 3; XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = XmlSchemaAttributeGroupRef.Read(reader, h); if (xmlSchemaAttributeGroupRef != null) { xmlSchemaComplexContentExtension.attributes.Add(xmlSchemaAttributeGroupRef); } continue; } } if (num <= 4 && reader.LocalName == "anyAttribute") { num = 5; XmlSchemaAnyAttribute xmlSchemaAnyAttribute = XmlSchemaAnyAttribute.Read(reader, h); if (xmlSchemaAnyAttribute != null) { xmlSchemaComplexContentExtension.AnyAttribute = xmlSchemaAnyAttribute; } } else { reader.RaiseInvalidElementError(); } } } return(xmlSchemaComplexContentExtension); }
public override void Check (ConformanceCheckContext ctx, XmlSchemaGroupRef value) { CheckSchemaQName (ctx, value, value.RefName); }
private void SetContainer(State state, object container) { switch (state) { case State.Root: break; case State.Schema: break; case State.Annotation: this.annotation = (XmlSchemaAnnotation)container; break; case State.Include: this.include = (XmlSchemaInclude)container; break; case State.Import: this.import = (XmlSchemaImport)container; break; case State.Element: this.element = (XmlSchemaElement)container; break; case State.Attribute: this.attribute = (XmlSchemaAttribute)container; break; case State.AttributeGroup: this.attributeGroup = (XmlSchemaAttributeGroup)container; break; case State.AttributeGroupRef: this.attributeGroupRef = (XmlSchemaAttributeGroupRef)container; break; case State.AnyAttribute: this.anyAttribute = (XmlSchemaAnyAttribute)container; break; case State.Group: this.group = (XmlSchemaGroup)container; break; case State.GroupRef: this.groupRef = (XmlSchemaGroupRef)container; break; case State.All: this.all = (XmlSchemaAll)container; break; case State.Choice: this.choice = (XmlSchemaChoice)container; break; case State.Sequence: this.sequence = (XmlSchemaSequence)container; break; case State.Any: this.anyElement = (XmlSchemaAny)container; break; case State.Notation: this.notation = (XmlSchemaNotation)container; break; case State.SimpleType: this.simpleType = (XmlSchemaSimpleType)container; break; case State.ComplexType: this.complexType = (XmlSchemaComplexType)container; break; case State.ComplexContent: this.complexContent = (XmlSchemaComplexContent)container; break; case State.ComplexContentExtension: this.complexContentExtension = (XmlSchemaComplexContentExtension)container; break; case State.ComplexContentRestriction: this.complexContentRestriction = (XmlSchemaComplexContentRestriction)container; break; case State.SimpleContent: this.simpleContent = (XmlSchemaSimpleContent)container; break; case State.SimpleContentExtension: this.simpleContentExtension = (XmlSchemaSimpleContentExtension)container; break; case State.SimpleContentRestriction: this.simpleContentRestriction = (XmlSchemaSimpleContentRestriction)container; break; case State.SimpleTypeUnion: this.simpleTypeUnion = (XmlSchemaSimpleTypeUnion)container; break; case State.SimpleTypeList: this.simpleTypeList = (XmlSchemaSimpleTypeList)container; break; case State.SimpleTypeRestriction: this.simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)container; break; case State.Unique: case State.Key: case State.KeyRef: this.identityConstraint = (XmlSchemaIdentityConstraint)container; break; case State.Selector: case State.Field: this.xpath = (XmlSchemaXPath)container; break; case State.MinExclusive: case State.MinInclusive: case State.MaxExclusive: case State.MaxInclusive: case State.TotalDigits: case State.FractionDigits: case State.Length: case State.MinLength: case State.MaxLength: case State.Enumeration: case State.Pattern: case State.WhiteSpace: this.facet = (XmlSchemaFacet)container; break; case State.AppInfo: this.appInfo = (XmlSchemaAppInfo)container; break; case State.Documentation: this.documentation = (XmlSchemaDocumentation)container; break; case State.Redefine: this.redefine = (XmlSchemaRedefine)container; break; default: Debug.Assert(false, "State is " + state); break; } }
/// <summary> /// Parses xs:group ref="..." elements in the schema /// </summary> /// <param name="groupRef"></param> /// <returns></returns> private RecursiveChildren ParseGoupRef(XmlSchemaGroupRef groupRef) { log.WriteLine("Parsing groupRef {0}", groupRef.RefName); using (log.Indent()) { return ParseGroupBase(groupRef.Particle); } }
internal static XmlSchemaGroupRef Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaGroupRef xmlSchemaGroupRef = new XmlSchemaGroupRef(); reader.MoveToElement(); if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "group") { XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaGroup.Read, name=" + reader.Name, null); reader.Skip(); return(null); } xmlSchemaGroupRef.LineNumber = reader.LineNumber; xmlSchemaGroupRef.LinePosition = reader.LinePosition; xmlSchemaGroupRef.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { xmlSchemaGroupRef.Id = reader.Value; } else if (reader.Name == "ref") { Exception ex; xmlSchemaGroupRef.refName = XmlSchemaUtil.ReadQNameAttribute(reader, out ex); if (ex != null) { XmlSchemaObject.error(h, reader.Value + " is not a valid value for ref attribute", ex); } } else if (reader.Name == "maxOccurs") { try { xmlSchemaGroupRef.MaxOccursString = reader.Value; } catch (Exception innerException) { XmlSchemaObject.error(h, reader.Value + " is an invalid value for maxOccurs", innerException); } } else if (reader.Name == "minOccurs") { try { xmlSchemaGroupRef.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 group", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaGroupRef); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(xmlSchemaGroupRef); } int num = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != "group") { XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaGroupRef.Read, name=" + reader.Name, null); } break; } if (num <= 1 && reader.LocalName == "annotation") { num = 2; XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h); if (xmlSchemaAnnotation != null) { xmlSchemaGroupRef.Annotation = xmlSchemaAnnotation; } } else { reader.RaiseInvalidElementError(); } } return(xmlSchemaGroupRef); }
public virtual void VisitXmlSchemaGroupRef(XmlSchemaGroupRef groupRef) { }
//<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); }
// <group // id = ID // ref = QName // minOccurs = ? : 1 // maxOccurs = ? : 1> // Content: (annotation?) // </group> internal static XmlSchemaGroupRef Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaGroupRef groupref = new XmlSchemaGroupRef(); 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); } groupref.LineNumber = reader.LineNumber; groupref.LinePosition = reader.LinePosition; groupref.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { groupref.Id = reader.Value; } else if (reader.Name == "ref") { Exception innerex; groupref.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 == "maxOccurs") { try { groupref.MaxOccursString = reader.Value; } catch (Exception e) { error(h, reader.Value + " is an invalid value for maxOccurs", e); } } else if (reader.Name == "minOccurs") { try { groupref.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 group", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, groupref); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(groupref); } // Content: (annotation?) int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaGroupRef.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) { groupref.Annotation = annotation; } continue; } reader.RaiseInvalidElementError(); } return(groupref); }
private XmlSchemaParticle CannonicalizeGroupRef(XmlSchemaGroupRef groupRef, bool root, bool substitution) { XmlSchemaGroup redefined; if (groupRef.Redefined != null) { redefined = groupRef.Redefined; } else { redefined = (XmlSchemaGroup) this.schema.Groups[groupRef.RefName]; } if (redefined == null) { base.SendValidationEvent("Sch_UndefGroupRef", groupRef.RefName.ToString(), groupRef); return XmlSchemaParticle.Empty; } if (redefined.CanonicalParticle == null) { this.CompileGroup(redefined); } if (redefined.CanonicalParticle == XmlSchemaParticle.Empty) { return XmlSchemaParticle.Empty; } XmlSchemaGroupBase canonicalParticle = (XmlSchemaGroupBase) redefined.CanonicalParticle; if (canonicalParticle is XmlSchemaAll) { if (!root) { base.SendValidationEvent("Sch_AllRefNotRoot", "", groupRef); return XmlSchemaParticle.Empty; } if ((groupRef.MinOccurs != 1M) || (groupRef.MaxOccurs != 1M)) { base.SendValidationEvent("Sch_AllRefMinMax", groupRef); return XmlSchemaParticle.Empty; } } else if ((canonicalParticle is XmlSchemaChoice) && (canonicalParticle.Items.Count == 0)) { if (groupRef.MinOccurs != 0M) { base.SendValidationEvent("Sch_EmptyChoice", groupRef, XmlSeverityType.Warning); } return XmlSchemaParticle.Empty; } XmlSchemaGroupBase base3 = (canonicalParticle is XmlSchemaSequence) ? ((XmlSchemaGroupBase) new XmlSchemaSequence()) : ((canonicalParticle is XmlSchemaChoice) ? ((XmlSchemaGroupBase) new XmlSchemaChoice()) : ((XmlSchemaGroupBase) new XmlSchemaAll())); base3.MinOccurs = groupRef.MinOccurs; base3.MaxOccurs = groupRef.MaxOccurs; for (int i = 0; i < canonicalParticle.Items.Count; i++) { base3.Items.Add((XmlSchemaParticle) canonicalParticle.Items[i]); } groupRef.SetParticle(base3); return base3; }
XmlCompletionDataCollection GetChildElementCompletionData(XmlSchemaGroupRef groupRef, string prefix) { XmlCompletionDataCollection data = new XmlCompletionDataCollection(); XmlSchemaGroup group = FindGroup(groupRef.RefName.Name); if (group != null) { XmlSchemaSequence sequence = group.Particle as XmlSchemaSequence; XmlSchemaChoice choice = group.Particle as XmlSchemaChoice; if(sequence != null) { data = GetChildElementCompletionData(sequence.Items, prefix); } else if (choice != null) { data = GetChildElementCompletionData(choice.Items, prefix); } } return data; }