protected override void Visit(XmlSchemaComplexContentExtension extension) { var baseType = _schemaSetManager.SchemaSet.GlobalTypes[extension.BaseTypeName] as XmlSchemaComplexType; if (baseType != null) { if (baseType.ContentType == XmlSchemaContentType.ElementOnly || baseType.ContentType == XmlSchemaContentType.Mixed) { if (extension.Particle == null) { Traverse(baseType); } else { PushNode(ChildType.Sequence, extension, null); Traverse(baseType); Traverse(extension.Particle); PopNode(); } return; } } if (extension.Particle != null) Traverse(extension.Particle); }
XObject[] CreateProtoComplexType(XmlSchemaComplexType complexType) { if (complexType.ContentModel != null) { if ((complexType.ContentModel as XmlSchemaSimpleContent) != null) { return CreateProtoSimpleContent((complexType.ContentModel as XmlSchemaSimpleContent), complexType.BaseXmlSchemaType).ToArray(); } else if ((complexType.ContentModel as XmlSchemaComplexContent) != null) { return CreateProtoComplexContent((complexType.ContentModel as XmlSchemaComplexContent), complexType.BaseXmlSchemaType).ToArray(); } else { throw new Exception("not implemented"); } } else { var complexContentExt = new XmlSchemaComplexContentExtension(); if (complexType.BaseXmlSchemaType != null) { complexContentExt.BaseTypeName = complexType.BaseXmlSchemaType.QualifiedName; } else { complexContentExt.BaseTypeName = null; } if (complexType.Attributes != null) { foreach (var i in complexType.Attributes) { complexContentExt.Attributes.Add(i); } } complexContentExt.Particle = complexType.Particle; var complexContent = new XmlSchemaComplexContent(); complexContent.Content = complexContentExt; return CreateProtoComplexContent(complexContent, complexType.BaseXmlSchemaType).ToArray(); } }
private Particle PopulateParticle(ComplexType ct) { if (ct.ContentModel == null) { if (ct.Particle == null) { ct.Particle = CreateSequence(); } return(ct.Particle); } ComplexModel cm = ct.ContentModel as ComplexModel; if (cm != null) { ComplexExt ce = cm.Content as ComplexExt; if (ce != null) { if (ce.Particle == null) { ce.Particle = CreateSequence(); } return(ce.Particle); } ComplexRst cr = cm.Content as ComplexRst; if (cr != null) { if (cr.Particle == null) { cr.Particle = CreateSequence(); } return(cr.Particle); } } throw Error(ct, "Schema inference internal error. The complexType should have been converted to have a complex content."); }
public static void AssertCompiledComplexContentExtension (XmlSchemaComplexContentExtension xccx, int attributeCount, bool hasAnyAttribute, XmlQualifiedName baseTypeName) { Assert.IsNotNull (xccx); Assert.AreEqual (attributeCount, xccx.Attributes.Count); Assert.AreEqual (hasAnyAttribute, xccx.AnyAttribute != null); Assert.AreEqual (baseTypeName, xccx.BaseTypeName); Assert.IsNotNull (xccx.Particle); }
protected void AssertCompiledComplexContentExtension (XmlSchemaComplexContentExtension xccx, int attributeCount, bool hasAnyAttribute, XmlQualifiedName baseTypeName) { AssertNotNull (xccx); AssertEquals (attributeCount, xccx.Attributes.Count); AssertEquals (hasAnyAttribute, xccx.AnyAttribute != null); AssertEquals (baseTypeName, xccx.BaseTypeName); AssertNotNull (xccx.Particle); }
private SOMList GetAttributes(ComplexType ct) { if (ct.ContentModel == null) { return(ct.Attributes); } SimpleModel sc = ct.ContentModel as SimpleModel; if (sc != null) { SimpleExt sce = sc.Content as SimpleExt; if (sce != null) { return(sce.Attributes); } SimpleRst scr = sc.Content as SimpleRst; if (scr != null) { return(scr.Attributes); } else { throw Error(sc, "Invalid simple content model."); } } ComplexModel cc = ct.ContentModel as ComplexModel; if (cc != null) { ComplexExt cce = cc.Content as ComplexExt; if (cce != null) { return(cce.Attributes); } ComplexRst ccr = cc.Content as ComplexRst; if (ccr != null) { return(ccr.Attributes); } else { throw Error(cc, "Invalid simple content model."); } } throw Error(cc, "Invalid complexType. Should not happen."); }
private void ToEmptiableComplexContent( ComplexModel cm, bool isNew) { ComplexExt ce = cm.Content as ComplexExt; if (ce != null) { if (ce.Particle != null) { ce.Particle.MinOccurs = 0; } else if (ce.BaseTypeName != null && ce.BaseTypeName != QName.Empty && ce.BaseTypeName != QNameAnyType) { throw Error(ce, "Complex type content extension has a reference to an external component that is not supported."); } } else { ComplexRst cr = cm.Content as ComplexRst; if (cr == null) { throw Error(cm, "Invalid complex content model was passed."); } if (cr.Particle != null) { cr.Particle.MinOccurs = 0; } else if (cr.BaseTypeName != null && cr.BaseTypeName != QName.Empty && cr.BaseTypeName != QNameAnyType) { throw Error(cr, "Complex type content extension has a reference to an external component that is not supported."); } } }
internal override int Compile(ValidationEventHandler h, XmlSchema schema) { if (this.CompilationId == schema.CompilationId) { return(0); } if (this.isRedefinedComponent) { if (base.Annotation != null) { base.Annotation.isRedefinedComponent = true; } if (this.Content != null) { this.Content.isRedefinedComponent = true; } } if (this.Content == null) { base.error(h, "Content must be present in a complexContent"); } else if (this.Content is XmlSchemaComplexContentRestriction) { XmlSchemaComplexContentRestriction xmlSchemaComplexContentRestriction = (XmlSchemaComplexContentRestriction)this.Content; this.errorCount += xmlSchemaComplexContentRestriction.Compile(h, schema); } else if (this.Content is XmlSchemaComplexContentExtension) { XmlSchemaComplexContentExtension xmlSchemaComplexContentExtension = (XmlSchemaComplexContentExtension)this.Content; this.errorCount += xmlSchemaComplexContentExtension.Compile(h, schema); } else { base.error(h, "complexContent can't have any value other than restriction or extention"); } XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h); this.CompilationId = schema.CompilationId; return(this.errorCount); }
internal XmlSchemaObject Clone(XmlSchema?parentSchema) { XmlSchemaComplexType complexType = (XmlSchemaComplexType)MemberwiseClone(); //Deep clone the QNames as these will be updated on chameleon includes if (complexType.ContentModel != null) { //simpleContent or complexContent XmlSchemaSimpleContent?simpleContent = complexType.ContentModel as XmlSchemaSimpleContent; if (simpleContent != null) { XmlSchemaSimpleContent newSimpleContent = (XmlSchemaSimpleContent)simpleContent.Clone(); XmlSchemaSimpleContentExtension?simpleExt = simpleContent.Content as XmlSchemaSimpleContentExtension; if (simpleExt != null) { XmlSchemaSimpleContentExtension newSimpleExt = (XmlSchemaSimpleContentExtension)simpleExt.Clone(); newSimpleExt.BaseTypeName = simpleExt.BaseTypeName.Clone(); newSimpleExt.SetAttributes(CloneAttributes(simpleExt.Attributes)); newSimpleContent.Content = newSimpleExt; } else { //simpleContent.Content is XmlSchemaSimpleContentRestriction XmlSchemaSimpleContentRestriction simpleRest = (XmlSchemaSimpleContentRestriction)simpleContent.Content !; XmlSchemaSimpleContentRestriction newSimpleRest = (XmlSchemaSimpleContentRestriction)simpleRest.Clone(); newSimpleRest.BaseTypeName = simpleRest.BaseTypeName.Clone(); newSimpleRest.SetAttributes(CloneAttributes(simpleRest.Attributes)); newSimpleContent.Content = newSimpleRest; } complexType.ContentModel = newSimpleContent; } else { // complexType.ContentModel is XmlSchemaComplexContent XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent)complexType.ContentModel; XmlSchemaComplexContent newComplexContent = (XmlSchemaComplexContent)complexContent.Clone(); XmlSchemaComplexContentExtension?complexExt = complexContent.Content as XmlSchemaComplexContentExtension; if (complexExt != null) { XmlSchemaComplexContentExtension newComplexExt = (XmlSchemaComplexContentExtension)complexExt.Clone(); newComplexExt.BaseTypeName = complexExt.BaseTypeName.Clone(); newComplexExt.SetAttributes(CloneAttributes(complexExt.Attributes)); if (HasParticleRef(complexExt.Particle, parentSchema)) { newComplexExt.Particle = CloneParticle(complexExt.Particle, parentSchema); } newComplexContent.Content = newComplexExt; } else { // complexContent.Content is XmlSchemaComplexContentRestriction XmlSchemaComplexContentRestriction complexRest = (complexContent.Content as XmlSchemaComplexContentRestriction) !; XmlSchemaComplexContentRestriction newComplexRest = (XmlSchemaComplexContentRestriction)complexRest.Clone(); newComplexRest.BaseTypeName = complexRest.BaseTypeName.Clone(); newComplexRest.SetAttributes(CloneAttributes(complexRest.Attributes)); if (HasParticleRef(newComplexRest.Particle, parentSchema)) { newComplexRest.Particle = CloneParticle(newComplexRest.Particle, parentSchema); } newComplexContent.Content = newComplexRest; } complexType.ContentModel = newComplexContent; } } else { //equals XmlSchemaComplexContent with baseType is anyType if (HasParticleRef(complexType.Particle, parentSchema)) { complexType.Particle = CloneParticle(complexType.Particle, parentSchema); } complexType.SetAttributes(CloneAttributes(complexType.Attributes)); } complexType.ClearCompiledState(); return(complexType); }
/// <summary> /// Creates an element representing a conditional "Switch" block, which recursively contains another type /// </summary> /// <param name="InnerType">The base type for the do block to contain</param> /// <returns>New schema element for the block</returns> static XmlSchemaElement CreateSwitchElement(ScriptSchemaStandardType InnerType) { // Create the "Option" element XmlSchemaComplexContentExtension CaseExtension = new XmlSchemaComplexContentExtension(); CaseExtension.BaseTypeName = GetQualifiedTypeName(InnerType); CaseExtension.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Required)); XmlSchemaComplexContent CaseContentModel = new XmlSchemaComplexContent(); CaseContentModel.Content = CaseExtension; XmlSchemaComplexType CaseSchemaType = new XmlSchemaComplexType(); CaseSchemaType.ContentModel = CaseContentModel; XmlSchemaElement CaseElement = new XmlSchemaElement(); CaseElement.Name = "Case"; CaseElement.SchemaType = CaseSchemaType; CaseElement.MinOccurs = 0; CaseElement.MaxOccursString = "unbounded"; // Create the "Otherwise" element XmlSchemaElement OtherwiseElement = new XmlSchemaElement(); OtherwiseElement.Name = "Default"; OtherwiseElement.SchemaTypeName = GetQualifiedTypeName(InnerType); OtherwiseElement.MinOccurs = 0; OtherwiseElement.MaxOccurs = 1; // Create the "Switch" element XmlSchemaSequence SwitchSequence = new XmlSchemaSequence(); SwitchSequence.Items.Add(CaseElement); SwitchSequence.Items.Add(OtherwiseElement); XmlSchemaComplexType SwitchSchemaType = new XmlSchemaComplexType(); SwitchSchemaType.Particle = SwitchSequence; XmlSchemaElement SwitchElement = new XmlSchemaElement(); SwitchElement.Name = "Switch"; SwitchElement.SchemaType = SwitchSchemaType; return SwitchElement; }
/// <summary> /// Creates an element representing a conditional "ForEach" block, which recursively contains another type /// </summary> /// <param name="InnerType">The base type for the foreach block to contain</param> /// <returns>New schema element for the block</returns> static XmlSchemaElement CreateForEachElement(ScriptSchemaStandardType InnerType) { XmlSchemaComplexContentExtension Extension = new XmlSchemaComplexContentExtension(); Extension.BaseTypeName = GetQualifiedTypeName(InnerType); Extension.Attributes.Add(CreateSchemaAttribute("Name", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Required)); Extension.Attributes.Add(CreateSchemaAttribute("Values", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Required)); Extension.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional)); XmlSchemaComplexContent ContentModel = new XmlSchemaComplexContent(); ContentModel.Content = Extension; XmlSchemaComplexType SchemaType = new XmlSchemaComplexType(); SchemaType.ContentModel = ContentModel; XmlSchemaElement Element = new XmlSchemaElement(); Element.Name = "ForEach"; Element.SchemaType = SchemaType; return Element; }
public virtual void Check (ConformanceCheckContext ctx, XmlSchemaComplexContentExtension value) {}
public override void Check (ConformanceCheckContext ctx, XmlSchemaComplexContentExtension value) { CheckSchemaQName (ctx, value, value.BaseTypeName); if (value.BaseTypeName.Namespace == "http://schemas.xmlsoap.org/soap/encoding/" && value.BaseTypeName.Name == "Array") ctx.ReportRuleViolation (value, BasicProfileRules.R2110); }
XmlCompletionItemCollection GetChildElementCompletion(XmlSchemaComplexContentExtension extension, string prefix) { XmlCompletionItemCollection completionItems; XmlSchemaComplexType complexType = FindNamedType(schema, extension.BaseTypeName); if (complexType != null) { completionItems = GetChildElementCompletion(complexType, prefix); } else { completionItems = new XmlCompletionItemCollection(); } // Add any elements. if (extension.Particle != null) { XmlSchemaSequence sequence = extension.Particle as XmlSchemaSequence; XmlSchemaChoice choice = extension.Particle as XmlSchemaChoice; XmlSchemaGroupRef groupRef = extension.Particle as XmlSchemaGroupRef; if(sequence != null) { completionItems.AddRange(GetChildElementCompletion(sequence.Items, prefix)); } else if (choice != null) { completionItems.AddRange(GetChildElementCompletion(choice.Items, prefix)); } else if (groupRef != null) { completionItems.AddRange(GetChildElementCompletion(groupRef, prefix)); } } return completionItems; }
/// <summary> /// Finds the named child element contained in the extension element. /// </summary> XmlSchemaElement FindChildElement(XmlSchemaComplexContentExtension extension, QualifiedName name) { XmlSchemaComplexType complexType = FindNamedType(schema, extension.BaseTypeName); if (complexType != null) { XmlSchemaElement matchedElement = FindChildElement(complexType, name); if (matchedElement == null) { XmlSchemaSequence sequence = extension.Particle as XmlSchemaSequence; XmlSchemaChoice choice = extension.Particle as XmlSchemaChoice; XmlSchemaGroupRef groupRef = extension.Particle as XmlSchemaGroupRef; if (sequence != null) { return FindElement(sequence.Items, name); } else if (choice != null) { return FindElement(choice.Items, name); } else if (groupRef != null) { return FindElement(groupRef, name); } } else { return matchedElement; } } return null; }
void ExportClassSchema (XmlTypeMapping map) { if (IsMapExported (map)) return; SetMapExported (map); if (map.TypeData.Type == typeof(object)) { foreach (XmlTypeMapping dmap in map.DerivedTypes) if (dmap.TypeData.SchemaType == SchemaTypes.Class) ExportClassSchema (dmap); return; } XmlSchema schema = GetSchema (map.XmlTypeNamespace); XmlSchemaComplexType stype = new XmlSchemaComplexType (); stype.Name = map.XmlType; schema.Items.Add (stype); ClassMap cmap = (ClassMap)map.ObjectMap; if (cmap.HasSimpleContent) { XmlSchemaSimpleContent simple = new XmlSchemaSimpleContent (); stype.ContentModel = simple; XmlSchemaSimpleContentExtension ext = new XmlSchemaSimpleContentExtension (); simple.Content = ext; XmlSchemaSequence particle; XmlSchemaAnyAttribute anyAttribute; ExportMembersMapSchema (schema, cmap, map.BaseMap, ext.Attributes, out particle, out anyAttribute); ext.AnyAttribute = anyAttribute; if (map.BaseMap == null) ext.BaseTypeName = cmap.SimpleContentBaseType; else { ext.BaseTypeName = new XmlQualifiedName (map.BaseMap.XmlType, map.BaseMap.XmlTypeNamespace); ImportNamespace (schema, map.BaseMap.XmlTypeNamespace); ExportClassSchema (map.BaseMap); } } else if (map.BaseMap != null && map.BaseMap.IncludeInSchema) { XmlSchemaComplexContent cstype = new XmlSchemaComplexContent (); XmlSchemaComplexContentExtension ext = new XmlSchemaComplexContentExtension (); ext.BaseTypeName = new XmlQualifiedName (map.BaseMap.XmlType, map.BaseMap.XmlTypeNamespace); cstype.Content = ext; stype.ContentModel = cstype; XmlSchemaSequence particle; XmlSchemaAnyAttribute anyAttribute; ExportMembersMapSchema (schema, cmap, map.BaseMap, ext.Attributes, out particle, out anyAttribute); ext.Particle = particle; ext.AnyAttribute = anyAttribute; stype.IsMixed = HasMixedContent (map); cstype.IsMixed = BaseHasMixedContent (map); ImportNamespace (schema, map.BaseMap.XmlTypeNamespace); ExportClassSchema (map.BaseMap); } else { XmlSchemaSequence particle; XmlSchemaAnyAttribute anyAttribute; ExportMembersMapSchema (schema, cmap, map.BaseMap, stype.Attributes, out particle, out anyAttribute); stype.Particle = particle; stype.AnyAttribute = anyAttribute; stype.IsMixed = cmap.XmlTextCollector != null; } foreach (XmlTypeMapping dmap in map.DerivedTypes) if (dmap.TypeData.SchemaType == SchemaTypes.Class) ExportClassSchema (dmap); }
void GetChildElementCompletionData (XmlCompletionDataList data, XmlSchemaComplexContentExtension extension, string prefix) { var complexType = FindNamedType (schema, extension.BaseTypeName); if (complexType != null) GetChildElementCompletionData (data, complexType, prefix); if (extension.Particle == null) return; var sequence = extension.Particle as XmlSchemaSequence; if (sequence != null) { GetChildElementCompletionData (data, sequence.Items, prefix); return; } var choice = extension.Particle as XmlSchemaChoice; if (choice != null) { GetChildElementCompletionData (data, choice.Items, prefix); return; } var groupRef = extension.Particle as XmlSchemaGroupRef; if (groupRef != null) { GetChildElementCompletionData (data, groupRef, prefix); return; } }
protected override void Visit(XmlSchemaComplexContentExtension extension) { // Does not have text. }
/// <summary> /// Creates the an xml schema for a complex type. This method automatically takes care of /// any base classes that must be added. /// <para /> /// This method already adds the <see cref="XmlSchemaComplexType" /> to the <see cref="XmlSchemaSet" />. /// </summary> /// <param name="type">The type to create the complex schema for.</param> /// <param name="schema">The schema.</param> /// <param name="schemaSet">The schema set.</param> /// <param name="serializationManager">The serialization manager.</param> /// <param name="generateFlatSchema">A value indicating whether the schema should be generated as flat schema.</param> /// <returns>The complex schema for the specified type.</returns> private static XmlSchemaComplexType CreateSchemaComplexType(Type type, XmlSchema schema, XmlSchemaSet schemaSet, ISerializationManager serializationManager, bool generateFlatSchema) { // Determine name, which is complex in generic types string typeName = GetTypeNameForSchema(type); // First, add the type, otherwise we might get into a stackoverflow when using generic base types // <xs:complexType> var modelBaseType = new XmlSchemaComplexType(); modelBaseType.Name = typeName; modelBaseType.IsMixed = false; schema.Items.Add(modelBaseType); var propertiesSequence = GetPropertiesSequence(type, schema, schemaSet, serializationManager); // If flat, don't generate base classes, just the type itself if (generateFlatSchema) { modelBaseType.Particle = propertiesSequence; return modelBaseType; } if (type.IsGenericType) { var genericComplexType = new XmlSchemaComplexType(); genericComplexType.Name = typeName; // <xs:annotation> var annotation = new XmlSchemaAnnotation(); // <xs:appinfo> var appInfo = new XmlSchemaAppInfo(); //<GenericType xmlns="http://schemas.microsoft.com/2003/10/Serialization/" Name="DataContractBaseOf{0}{#}" Namespace="http://schemas.datacontract.org/2004/07/STC"> // <GenericParameter Name="ProfileDateRange2" Namespace="http://schemas.datacontract.org/2004/07/STC.Meter.ProfileData"/> //</GenericType> var genericTypeElement = new XElement("GenericType"); genericTypeElement.Add(new XAttribute("Name", string.Format("{0}Of{{0}}{{#}}", typeName))); genericTypeElement.Add(new XAttribute("Namespace", GetTypeNamespaceForSchema(type))); foreach (var genericArgument in type.GetGenericArgumentsEx()) { var genericArgumentQualifiedName = AddTypeToSchemaSet(genericArgument, schemaSet, serializationManager); var genericArgumentElement = new XElement("GenericParameter"); genericArgumentElement.Add(new XAttribute("Name", genericArgumentQualifiedName.Name)); genericArgumentElement.Add(new XAttribute("Namespace", genericArgumentQualifiedName.Namespace)); genericTypeElement.Add(genericArgumentElement); } var conversionDoc = new XmlDocument(); appInfo.Markup = new XmlNode[] { conversionDoc.CreateTextNode(genericTypeElement.ToString()) }; annotation.Items.Add(appInfo); } var baseTypeQualifiedName = AddTypeToSchemaSet(type.BaseType, schemaSet, serializationManager); if (baseTypeQualifiedName != null) { // <xs:extensions base="address"> var complexContentExtension = new XmlSchemaComplexContentExtension(); complexContentExtension.BaseTypeName = baseTypeQualifiedName; complexContentExtension.Particle = propertiesSequence; // <xs:complexContent> var complexContent = new XmlSchemaComplexContent(); complexContent.Content = complexContentExtension; modelBaseType.ContentModel = complexContent; } return modelBaseType; }
protected override void Visit(XmlSchemaComplexContentExtension extension) { ProcessExtension(extension.BaseTypeName, extension.Attributes, extension.AnyAttribute); }
XmlCompletionDataCollection GetAttributeCompletionData(XmlSchemaComplexContentExtension extension) { XmlCompletionDataCollection data = new XmlCompletionDataCollection(); data.AddRange(GetAttributeCompletionData(extension.Attributes)); XmlSchemaComplexType baseComplexType = FindNamedType(schema, extension.BaseTypeName); if (baseComplexType != null) { data.AddRange(GetAttributeCompletionData(baseComplexType)); } return data; }
/// <summary> /// Handle derivation by extension. /// If type is null, it'll create a new complexType /// with an XmlAny node in its sequence child node. /// </summary> public XmlSchemaType WriteComplexSchemaType (Type type) { // // Recursively generate schema for all parent types // if (type != null && type.BaseType == typeof (object)) return WriteSchemaType (type); XmlSchemaComplexType complexType = new XmlSchemaComplexType (); XmlSchemaSequence sequence; XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension (); XmlSchemaComplexContent content = new XmlSchemaComplexContent (); complexType.ContentModel = content; content.Content = extension; XmlSchemaType baseSchemaType = WriteSchemaType (type.BaseType); complexType.Name = type.Name; FieldInfo [] fields = type.GetFields (flags); PropertyInfo [] properties = type.GetProperties (flags); try { sequence = PopulateSequence (fields, properties); if (attributes != null) { foreach (object o in attributes) { MemberInfo member = (MemberInfo) o; Type attribute_type = (Type) attributes [o]; complexType.Attributes.Add (WriteSchemaAttribute (member, attribute_type)); } } } catch (ArgumentException e) { throw new ArgumentException (String.Format ("There is an error in '{0}'\n\t{1}", type.Name, e.Message)); } extension.BaseTypeName = new XmlQualifiedName (baseSchemaType.Name); extension.Particle = sequence; generatedSchemaTypes.Add (type.FullName, complexType); return complexType; }
XmlQualifiedName ExportStructMapping(StructMapping mapping, string ns, XmlSchemaElement element) { if (mapping.TypeDesc.IsRoot) { needToExportRoot = true; return XmlQualifiedName.Empty; } if (mapping.IsAnonymousType) { if (references[mapping] != null) throw new InvalidOperationException(Res.GetString(Res.XmlCircularReference2, mapping.TypeDesc.Name, "AnonymousType", "false")); references[mapping] = mapping; } XmlSchemaComplexType type = (XmlSchemaComplexType)types[mapping]; if (type == null) { if (!mapping.IncludeInSchema) throw new InvalidOperationException(Res.GetString(Res.XmlCannotIncludeInSchema, mapping.TypeDesc.Name)); CheckForDuplicateType(mapping, mapping.Namespace); type = new XmlSchemaComplexType(); if (!mapping.IsAnonymousType) { type.Name = mapping.TypeName; AddSchemaItem(type, mapping.Namespace, ns); types.Add(mapping, type); } type.IsAbstract = mapping.TypeDesc.IsAbstract; bool openModel = mapping.IsOpenModel; if (mapping.BaseMapping != null && mapping.BaseMapping.IncludeInSchema) { if (mapping.BaseMapping.IsAnonymousType) { throw new InvalidOperationException(Res.GetString(Res.XmlAnonymousBaseType, mapping.TypeDesc.Name, mapping.BaseMapping.TypeDesc.Name, "AnonymousType", "false")); } if (mapping.HasSimpleContent) { XmlSchemaSimpleContent model = new XmlSchemaSimpleContent(); XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension(); extension.BaseTypeName = ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null); model.Content = extension; type.ContentModel = model; } else { XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension(); extension.BaseTypeName = ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null); XmlSchemaComplexContent model = new XmlSchemaComplexContent(); model.Content = extension; model.IsMixed = XmlSchemaImporter.IsMixed((XmlSchemaComplexType)types[mapping.BaseMapping]); type.ContentModel = model; } openModel = false; } ExportTypeMembers(type, mapping.Members, mapping.TypeName, mapping.Namespace, mapping.HasSimpleContent, openModel); ExportDerivedMappings(mapping); if (mapping.XmlnsMember != null) { AddXmlnsAnnotation(type, mapping.XmlnsMember.Name); } } else { AddSchemaImport(mapping.Namespace, ns); } if (mapping.IsAnonymousType) { references[mapping] = null; if (element != null) element.SchemaType = type; return XmlQualifiedName.Empty; } else { XmlQualifiedName qname = new XmlQualifiedName(type.Name, mapping.Namespace); if (element != null) element.SchemaTypeName = qname; return qname; } }
void GetAttributeCompletionData (XmlCompletionDataList data, XmlSchemaComplexContentExtension extension) { GetAttributeCompletionData (data, extension.Attributes); var baseComplexType = FindNamedType (schema, extension.BaseTypeName); if (baseComplexType != null) GetAttributeCompletionData (data, baseComplexType); }
XmlSchemaAttribute FindAttribute(XmlSchemaComplexContentExtension extension, string name) { return FindAttribute(extension.Attributes, name); }
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); }
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaComplexContentExtension extension, XmlNamespaceCollection namespacesInScope) { XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection(); completionItems.AddRange(GetAttributeCompletion(extension.Attributes, namespacesInScope)); completionItems.AddRange(GetBaseComplexTypeAttributeCompletion(extension.BaseTypeName, namespacesInScope)); return completionItems; }
private void CompileComplexContentExtension(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaComplexContentExtension complexExtension) { XmlSchemaComplexType baseType = null; if (complexType.Redefined != null && complexExtension.BaseTypeName == complexType.Redefined.QualifiedName) { baseType = (XmlSchemaComplexType)complexType.Redefined; CompileComplexType(baseType); } else { baseType = GetComplexType(complexExtension.BaseTypeName); if (baseType == null) { SendValidationEvent(Res.Sch_UndefBaseExtension, complexExtension.BaseTypeName.ToString(), complexExtension); return; } } if ((baseType.FinalResolved & XmlSchemaDerivationMethod.Extension) != 0) { SendValidationEvent(Res.Sch_BaseFinalExtension, complexType); } CompileLocalAttributes(baseType, complexType, complexExtension.Attributes, complexExtension.AnyAttribute, XmlSchemaDerivationMethod.Extension); XmlSchemaParticle baseParticle = baseType.ContentTypeParticle; XmlSchemaParticle extendedParticle = CannonicalizeParticle(complexExtension.Particle, true); if (baseParticle != XmlSchemaParticle.Empty) { if (extendedParticle != XmlSchemaParticle.Empty) { XmlSchemaSequence compiledParticle = new XmlSchemaSequence(); compiledParticle.Items.Add(baseParticle); compiledParticle.Items.Add(extendedParticle); complexType.SetContentTypeParticle(CompileContentTypeParticle(compiledParticle)); } else { complexType.SetContentTypeParticle(baseParticle); } } else { complexType.SetContentTypeParticle(extendedParticle); } XmlSchemaContentType contentType = GetSchemaContentType(complexType, complexContent, extendedParticle); if (contentType == XmlSchemaContentType.Empty) { //Derived content type is empty, Get ContentType from base contentType = baseType.ContentType; // In case of a simple base type (content type is TextOnly) the derived type // will be the same as the base type. So set the same content type and then also // set the same data type. if (contentType == XmlSchemaContentType.TextOnly) { complexType.SetDatatype(baseType.Datatype); } } complexType.SetContentType(contentType); if (baseType.ContentType != XmlSchemaContentType.Empty && complexType.ContentType != baseType.ContentType) { //If base is empty, do not check SendValidationEvent(Res.Sch_DifContentType, complexType); return; } complexType.SetBaseSchemaType(baseType); complexType.SetDerivedBy(XmlSchemaDerivationMethod.Extension); }
internal static XmlSchemaComplexContent Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaComplexContent xmlSchemaComplexContent = new XmlSchemaComplexContent(); reader.MoveToElement(); if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "complexContent") { XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaComplexContent.Read, name=" + reader.Name, null); reader.Skip(); return(null); } xmlSchemaComplexContent.LineNumber = reader.LineNumber; xmlSchemaComplexContent.LinePosition = reader.LinePosition; xmlSchemaComplexContent.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { xmlSchemaComplexContent.Id = reader.Value; } else if (reader.Name == "mixed") { Exception ex; xmlSchemaComplexContent.isMixed = XmlSchemaUtil.ReadBoolAttribute(reader, out ex); if (ex != null) { XmlSchemaObject.error(h, reader.Value + " is an invalid value for mixed", ex); } } 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 complexContent", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaComplexContent); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(xmlSchemaComplexContent); } int num = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != "complexContent") { XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaComplexContent.Read, name=" + reader.Name, null); } break; } if (num <= 1 && reader.LocalName == "annotation") { num = 2; XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h); if (xmlSchemaAnnotation != null) { xmlSchemaComplexContent.Annotation = xmlSchemaAnnotation; } } else { if (num <= 2) { if (reader.LocalName == "restriction") { num = 3; XmlSchemaComplexContentRestriction xmlSchemaComplexContentRestriction = XmlSchemaComplexContentRestriction.Read(reader, h); if (xmlSchemaComplexContentRestriction != null) { xmlSchemaComplexContent.content = xmlSchemaComplexContentRestriction; } continue; } if (reader.LocalName == "extension") { num = 3; XmlSchemaComplexContentExtension xmlSchemaComplexContentExtension = XmlSchemaComplexContentExtension.Read(reader, h); if (xmlSchemaComplexContentExtension != null) { xmlSchemaComplexContent.content = xmlSchemaComplexContentExtension; } continue; } } reader.RaiseInvalidElementError(); } } return(xmlSchemaComplexContent); }
//<complexContent // id = ID // mixed = boolean // {any attributes with non-schema namespace . . .}> // Content: (annotation?, (restriction | extension)) //</complexContent> internal static XmlSchemaComplexContent Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaComplexContent complex = new XmlSchemaComplexContent(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaComplexContent.Read, name=" + reader.Name, null); reader.Skip(); return(null); } complex.LineNumber = reader.LineNumber; complex.LinePosition = reader.LinePosition; complex.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { complex.Id = reader.Value; } else if (reader.Name == "mixed") { Exception innerex; complex.isMixed = XmlSchemaUtil.ReadBoolAttribute(reader, out innerex); if (innerex != null) { error(h, reader.Value + " is an invalid value for mixed", innerex); } } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for complexContent", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, complex); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(complex); } //Content: (annotation?, (restriction | extension)) int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaComplexContent.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) { complex.Annotation = annotation; } continue; } if (level <= 2) { if (reader.LocalName == "restriction") { level = 3; XmlSchemaComplexContentRestriction restriction = XmlSchemaComplexContentRestriction.Read(reader, h); if (restriction != null) { complex.content = restriction; } continue; } if (reader.LocalName == "extension") { level = 3; XmlSchemaComplexContentExtension extension = XmlSchemaComplexContentExtension.Read(reader, h); if (extension != null) { complex.content = extension; } continue; } } reader.RaiseInvalidElementError(); } return(complex); }
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; } }
XmlQualifiedName ExportStructMapping(StructMapping mapping, string ns) { if (mapping.TypeDesc.IsRoot) return ExportRootMapping(mapping); XmlSchemaComplexType type = (XmlSchemaComplexType)types[mapping]; if (type == null) { if (!mapping.IncludeInSchema) throw new InvalidOperationException(Res.GetString(Res.XmlSoapCannotIncludeInSchema, mapping.TypeDesc.Name)); CheckForDuplicateType(mapping.TypeName, mapping.Namespace); type = new XmlSchemaComplexType(); type.Name = mapping.TypeName; types.Add(mapping, type); AddSchemaItem(type, mapping.Namespace, ns); type.IsAbstract = mapping.TypeDesc.IsAbstract; if (mapping.BaseMapping != null && mapping.BaseMapping.IncludeInSchema) { XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension(); extension.BaseTypeName = ExportStructMapping(mapping.BaseMapping, mapping.Namespace); XmlSchemaComplexContent model = new XmlSchemaComplexContent(); model.Content = extension; type.ContentModel = model; } ExportTypeMembers(type, mapping.Members, mapping.Namespace); ExportDerivedMappings(mapping); } else { AddSchemaImport(mapping.Namespace, ns); } return new XmlQualifiedName(type.Name, mapping.Namespace); }
private XmlQualifiedName ExportStructMapping(StructMapping mapping, string ns, XmlSchemaElement element) { if (mapping.TypeDesc.IsRoot) { this.needToExportRoot = true; return XmlQualifiedName.Empty; } if (mapping.IsAnonymousType) { if (this.references[mapping] != null) { throw new InvalidOperationException(Res.GetString("XmlCircularReference2", new object[] { mapping.TypeDesc.Name, "AnonymousType", "false" })); } this.references[mapping] = mapping; } XmlSchemaComplexType item = (XmlSchemaComplexType) this.types[mapping]; if (item == null) { if (!mapping.IncludeInSchema) { throw new InvalidOperationException(Res.GetString("XmlCannotIncludeInSchema", new object[] { mapping.TypeDesc.Name })); } this.CheckForDuplicateType(mapping, mapping.Namespace); item = new XmlSchemaComplexType(); if (!mapping.IsAnonymousType) { item.Name = mapping.TypeName; this.AddSchemaItem(item, mapping.Namespace, ns); this.types.Add(mapping, item); } item.IsAbstract = mapping.TypeDesc.IsAbstract; bool isOpenModel = mapping.IsOpenModel; if ((mapping.BaseMapping != null) && mapping.BaseMapping.IncludeInSchema) { if (mapping.BaseMapping.IsAnonymousType) { throw new InvalidOperationException(Res.GetString("XmlAnonymousBaseType", new object[] { mapping.TypeDesc.Name, mapping.BaseMapping.TypeDesc.Name, "AnonymousType", "false" })); } if (mapping.HasSimpleContent) { XmlSchemaSimpleContent content = new XmlSchemaSimpleContent(); XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension { BaseTypeName = this.ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null) }; content.Content = extension; item.ContentModel = content; } else { XmlSchemaComplexContentExtension extension2 = new XmlSchemaComplexContentExtension { BaseTypeName = this.ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null) }; XmlSchemaComplexContent content2 = new XmlSchemaComplexContent { Content = extension2, IsMixed = XmlSchemaImporter.IsMixed((XmlSchemaComplexType) this.types[mapping.BaseMapping]) }; item.ContentModel = content2; } isOpenModel = false; } this.ExportTypeMembers(item, mapping.Members, mapping.TypeName, mapping.Namespace, mapping.HasSimpleContent, isOpenModel); this.ExportDerivedMappings(mapping); if (mapping.XmlnsMember != null) { this.AddXmlnsAnnotation(item, mapping.XmlnsMember.Name); } } else { this.AddSchemaImport(mapping.Namespace, ns); } if (mapping.IsAnonymousType) { this.references[mapping] = null; if (element != null) { element.SchemaType = item; } return XmlQualifiedName.Empty; } XmlQualifiedName name = new XmlQualifiedName(item.Name, mapping.Namespace); if (element != null) { element.SchemaTypeName = name; } return name; }
void Write42_XmlSchemaComplexContentExtension(XmlSchemaComplexContentExtension o) { if ((object)o == null) return; WriteStartElement("extension"); WriteAttribute(@"id", @"", ((System.String)o.@Id)); WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o); if ([email protected]){ WriteAttribute(@"base", @"", o.@BaseTypeName); } Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation); if (o.@Particle is XmlSchemaSequence) { Write54_XmlSchemaSequence((XmlSchemaSequence)o.@Particle); } else if (o.@Particle is XmlSchemaGroupRef) { Write55_XmlSchemaGroupRef((XmlSchemaGroupRef)o.@Particle); } else if (o.@Particle is XmlSchemaChoice) { Write52_XmlSchemaChoice((XmlSchemaChoice)o.@Particle); } else if (o.@Particle is XmlSchemaAll) { Write43_XmlSchemaAll((XmlSchemaAll)o.@Particle); } WriteSortedItems(o.Attributes); Write33_XmlSchemaAnyAttribute((XmlSchemaAnyAttribute)o.@AnyAttribute); WriteEndElement(); }
/// <summary> /// Finds the named child element contained in the extension element. /// </summary> XmlSchemaElement FindChildElement (XmlSchemaComplexContentExtension extension, QualifiedName name) { var complexType = FindNamedType (schema, extension.BaseTypeName); if (complexType == null) return null; var matchedElement = FindChildElement (complexType, name); if (matchedElement != null) return matchedElement; var sequence = extension.Particle as XmlSchemaSequence; if (sequence != null) return FindElement (sequence.Items, name); var choice = extension.Particle as XmlSchemaChoice; if (choice != null) return FindElement (choice.Items, name); var groupRef = extension.Particle as XmlSchemaGroupRef; if (groupRef != null) return FindElement (groupRef, name); return null; }
internal XmlSchemaObject Clone(XmlSchema parentSchema) { XmlSchemaComplexType type = (XmlSchemaComplexType) base.MemberwiseClone(); if (type.ContentModel != null) { XmlSchemaSimpleContent contentModel = type.ContentModel as XmlSchemaSimpleContent; if (contentModel != null) { XmlSchemaSimpleContent content2 = (XmlSchemaSimpleContent) contentModel.Clone(); XmlSchemaSimpleContentExtension content = contentModel.Content as XmlSchemaSimpleContentExtension; if (content != null) { XmlSchemaSimpleContentExtension extension2 = (XmlSchemaSimpleContentExtension) content.Clone(); extension2.BaseTypeName = content.BaseTypeName.Clone(); extension2.SetAttributes(CloneAttributes(content.Attributes)); content2.Content = extension2; } else { XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) contentModel.Content; XmlSchemaSimpleContentRestriction restriction2 = (XmlSchemaSimpleContentRestriction) restriction.Clone(); restriction2.BaseTypeName = restriction.BaseTypeName.Clone(); restriction2.SetAttributes(CloneAttributes(restriction.Attributes)); content2.Content = restriction2; } type.ContentModel = content2; } else { XmlSchemaComplexContent content3 = (XmlSchemaComplexContent) type.ContentModel; XmlSchemaComplexContent content4 = (XmlSchemaComplexContent) content3.Clone(); XmlSchemaComplexContentExtension extension3 = content3.Content as XmlSchemaComplexContentExtension; if (extension3 != null) { XmlSchemaComplexContentExtension extension4 = (XmlSchemaComplexContentExtension) extension3.Clone(); extension4.BaseTypeName = extension3.BaseTypeName.Clone(); extension4.SetAttributes(CloneAttributes(extension3.Attributes)); if (HasParticleRef(extension3.Particle, parentSchema)) { extension4.Particle = CloneParticle(extension3.Particle, parentSchema); } content4.Content = extension4; } else { XmlSchemaComplexContentRestriction restriction3 = content3.Content as XmlSchemaComplexContentRestriction; XmlSchemaComplexContentRestriction restriction4 = (XmlSchemaComplexContentRestriction) restriction3.Clone(); restriction4.BaseTypeName = restriction3.BaseTypeName.Clone(); restriction4.SetAttributes(CloneAttributes(restriction3.Attributes)); if (HasParticleRef(restriction4.Particle, parentSchema)) { restriction4.Particle = CloneParticle(restriction4.Particle, parentSchema); } content4.Content = restriction4; } type.ContentModel = content4; } } else { if (HasParticleRef(type.Particle, parentSchema)) { type.Particle = CloneParticle(type.Particle, parentSchema); } type.SetAttributes(CloneAttributes(type.Attributes)); } type.ClearCompiledState(); return type; }
//<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); }
/// <summary> /// Creates the schema type representing the agent type /// </summary> /// <returns>Type definition for an agent</returns> static XmlSchemaType CreateAgentType() { XmlSchemaComplexContentExtension Extension = new XmlSchemaComplexContentExtension(); Extension.BaseTypeName = GetQualifiedTypeName(ScriptSchemaStandardType.AgentBody); Extension.Attributes.Add(CreateSchemaAttribute("Name", StringTypeName, XmlSchemaUse.Required)); Extension.Attributes.Add(CreateSchemaAttribute("Type", ScriptSchemaStandardType.NameList, XmlSchemaUse.Optional)); Extension.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional)); XmlSchemaComplexContent ContentModel = new XmlSchemaComplexContent(); ContentModel.Content = Extension; XmlSchemaComplexType ComplexType = new XmlSchemaComplexType(); ComplexType.Name = GetTypeName(ScriptSchemaStandardType.Agent); ComplexType.ContentModel = ContentModel; return ComplexType; }
private void CompileComplexContentExtension(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaComplexContentExtension complexExtension) { XmlSchemaComplexType redefined = null; if ((complexType.Redefined != null) && (complexExtension.BaseTypeName == complexType.Redefined.QualifiedName)) { redefined = (XmlSchemaComplexType) complexType.Redefined; this.CompileComplexType(redefined); } else { redefined = this.GetComplexType(complexExtension.BaseTypeName); if (redefined == null) { base.SendValidationEvent("Sch_UndefBaseExtension", complexExtension.BaseTypeName.ToString(), complexExtension); return; } } if (((redefined != null) && (redefined.ElementDecl != null)) && (redefined.ContentType == XmlSchemaContentType.TextOnly)) { base.SendValidationEvent("Sch_NotComplexContent", complexType); } else { complexType.SetBaseSchemaType(redefined); if ((redefined.FinalResolved & XmlSchemaDerivationMethod.Extension) != XmlSchemaDerivationMethod.Empty) { base.SendValidationEvent("Sch_BaseFinalExtension", complexType); } this.CompileLocalAttributes(redefined, complexType, complexExtension.Attributes, complexExtension.AnyAttribute, XmlSchemaDerivationMethod.Extension); XmlSchemaParticle contentTypeParticle = redefined.ContentTypeParticle; XmlSchemaParticle item = this.CannonicalizeParticle(complexExtension.Particle, true, true); if (contentTypeParticle != XmlSchemaParticle.Empty) { if (item != XmlSchemaParticle.Empty) { XmlSchemaSequence particle = new XmlSchemaSequence(); particle.Items.Add(contentTypeParticle); particle.Items.Add(item); complexType.SetContentTypeParticle(this.CompileContentTypeParticle(particle, false)); } else { complexType.SetContentTypeParticle(contentTypeParticle); } XmlSchemaContentType contentType = this.GetSchemaContentType(complexType, complexContent, item); if (contentType == XmlSchemaContentType.Empty) { contentType = redefined.ContentType; } complexType.SetContentType(contentType); if (complexType.ContentType != redefined.ContentType) { base.SendValidationEvent("Sch_DifContentType", complexType); } } else { complexType.SetContentTypeParticle(item); complexType.SetContentType(this.GetSchemaContentType(complexType, complexContent, complexType.ContentTypeParticle)); } complexType.SetDerivedBy(XmlSchemaDerivationMethod.Extension); } }
/// <summary> /// Creates the schema type representing the node type /// </summary> /// <returns>Type definition for a node</returns> static XmlSchemaType CreateNodeType() { XmlSchemaComplexContentExtension Extension = new XmlSchemaComplexContentExtension(); Extension.BaseTypeName = GetQualifiedTypeName(ScriptSchemaStandardType.NodeBody); Extension.Attributes.Add(CreateSchemaAttribute("Name", ScriptSchemaStandardType.Name, XmlSchemaUse.Required)); Extension.Attributes.Add(CreateSchemaAttribute("Requires", ScriptSchemaStandardType.NameOrTagList, XmlSchemaUse.Optional)); Extension.Attributes.Add(CreateSchemaAttribute("Produces", ScriptSchemaStandardType.TagList, XmlSchemaUse.Optional)); Extension.Attributes.Add(CreateSchemaAttribute("After", ScriptSchemaStandardType.NameOrTagList, XmlSchemaUse.Optional)); Extension.Attributes.Add(CreateSchemaAttribute("Token", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional)); Extension.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional)); Extension.Attributes.Add(CreateSchemaAttribute("NotifyOnWarnings", ScriptSchemaStandardType.Boolean, XmlSchemaUse.Optional)); XmlSchemaComplexContent ContentModel = new XmlSchemaComplexContent(); ContentModel.Content = Extension; XmlSchemaComplexType ComplexType = new XmlSchemaComplexType(); ComplexType.Name = GetTypeName(ScriptSchemaStandardType.Node); ComplexType.ContentModel = ContentModel; return ComplexType; }