internal void ReflectStringParametersMessage() { Message inputMessage = InputMessage; foreach (ParameterInfo parameterInfo in Method.InParameters) { MessagePart part = new MessagePart(); part.Name = XmlConvert.EncodeLocalName(parameterInfo.Name); if (parameterInfo.ParameterType.IsArray) { string typeNs = DefaultNamespace; if (typeNs.EndsWith("/", StringComparison.Ordinal)) { typeNs += "AbstractTypes"; } else { typeNs += "/AbstractTypes"; } string typeName = "StringArray"; if (!ServiceDescription.Types.Schemas.Contains(typeNs)) { XmlSchema schema = new XmlSchema(); schema.TargetNamespace = typeNs; ServiceDescription.Types.Schemas.Add(schema); XmlSchemaElement element = new XmlSchemaElement(); element.Name = "String"; element.SchemaTypeName = new XmlQualifiedName("string", XmlSchema.Namespace); element.MinOccurs = decimal.Zero; element.MaxOccurs = decimal.MaxValue; XmlSchemaSequence all = new XmlSchemaSequence(); all.Items.Add(element); XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction(); restriction.BaseTypeName = new XmlQualifiedName(Soap.ArrayType, Soap.Encoding); restriction.Particle = all; XmlSchemaImport import = new XmlSchemaImport(); import.Namespace = restriction.BaseTypeName.Namespace; XmlSchemaComplexContent model = new XmlSchemaComplexContent(); model.Content = restriction; XmlSchemaComplexType type = new XmlSchemaComplexType(); type.Name = typeName; type.ContentModel = model; schema.Items.Add(type); schema.Includes.Add(import); } part.Type = new XmlQualifiedName(typeName, typeNs); } else { part.Type = new XmlQualifiedName("string", XmlSchema.Namespace); } inputMessage.Parts.Add(part); } }
public override void AddItemElementToArrayElement(XmlSchemaElement arrayElement, XmlSchemaElement itemElement, Action <string> addSchemaImport) { addSchemaImport(NamespaceConstants.SOAP_ENC); var schemaAttribute = new XmlSchemaAttribute { RefName = new XmlQualifiedName("arrayType", NamespaceConstants.SOAP_ENC) }; if (itemElement.SchemaTypeName != null) { var attribute = CreateArrayTypeAttribute(XName.Get(itemElement.SchemaTypeName.Name, itemElement.SchemaTypeName.Namespace)); schemaAttribute.UnhandledAttributes = new[] { attribute }; } var restriction = new XmlSchemaComplexContentRestriction { BaseTypeName = new XmlQualifiedName("Array", NamespaceConstants.SOAP_ENC), Particle = new XmlSchemaSequence { Items = { itemElement } }, Attributes = { schemaAttribute } }; arrayElement.SchemaType = new XmlSchemaComplexType { ContentModel = new XmlSchemaComplexContent { Content = restriction } }; }
private void Write56_XmlSchemaComplexContentRestriction(XmlSchemaComplexContentRestriction o) { if (o != null) { this.WriteStartElement("restriction"); this.WriteAttribute("id", "", o.Id); this.WriteAttributes(o.UnhandledAttributes, o); if (!o.BaseTypeName.IsEmpty) { this.WriteAttribute("base", "", o.BaseTypeName); } this.Write5_XmlSchemaAnnotation(o.Annotation); if (o.Particle is XmlSchemaSequence) { this.Write54_XmlSchemaSequence((XmlSchemaSequence)o.Particle); } else if (o.Particle is XmlSchemaGroupRef) { this.Write55_XmlSchemaGroupRef((XmlSchemaGroupRef)o.Particle); } else if (o.Particle is XmlSchemaChoice) { this.Write52_XmlSchemaChoice((XmlSchemaChoice)o.Particle); } else if (o.Particle is XmlSchemaAll) { this.Write43_XmlSchemaAll((XmlSchemaAll)o.Particle); } this.WriteSortedItems(o.Attributes); this.Write33_XmlSchemaAnyAttribute(o.AnyAttribute); this.WriteEndElement(); } }
internal static XmlSchema BuildSchema(DiscoveryVersion version) { var schema = new XmlSchema() { TargetNamespace = version.Namespace }; var ccr = new XmlSchemaComplexContentRestriction(); ccr.Attributes.Add(new XmlSchemaAttribute() { Name = "InstanceId", SchemaTypeName = new XmlQualifiedName("unsignedInt", XmlSchema.Namespace), Use = XmlSchemaUse.Required }); ccr.Attributes.Add(new XmlSchemaAttribute() { Name = "SequenceId", SchemaTypeName = new XmlQualifiedName("anyURI", XmlSchema.Namespace), Use = XmlSchemaUse.Optional }); ccr.Attributes.Add(new XmlSchemaAttribute() { Name = "MessageNumber", SchemaTypeName = new XmlQualifiedName("unsignedInt", XmlSchema.Namespace), Use = XmlSchemaUse.Required }); var ct = new XmlSchemaComplexType() { Name = "AppSequenceType", ContentModel = new XmlSchemaComplexContent() { Content = ccr } }; schema.Items.Add(ct); return(schema); }
void GetChildElementCompletionData(XmlCompletionDataList data, XmlSchemaComplexContentRestriction restriction, string prefix) { if (restriction.Particle == null) { return; } var sequence = restriction.Particle as XmlSchemaSequence; if (sequence != null) { GetChildElementCompletionData(data, sequence.Items, prefix); return; } var choice = restriction.Particle as XmlSchemaChoice; if (choice != null) { GetChildElementCompletionData(data, choice.Items, prefix); return; } var groupRef = restriction.Particle as XmlSchemaGroupRef; if (groupRef != null) { GetChildElementCompletionData(data, groupRef, prefix); return; } }
static void AddAttributeToXmlSchema(XmlSchemaComplexContentRestriction restriction, UxmlAttributeDescription description, XmlQualifiedName typeName) { XmlSchemaAttribute attr = new XmlSchemaAttribute(); attr.Name = description.name; attr.SchemaTypeName = typeName; switch (description.use) { case UxmlAttributeDescription.Use.Optional: attr.Use = XmlSchemaUse.Optional; attr.DefaultValue = description.defaultValueAsString; break; case UxmlAttributeDescription.Use.Prohibited: attr.Use = XmlSchemaUse.Prohibited; break; case UxmlAttributeDescription.Use.Required: attr.Use = XmlSchemaUse.Required; break; default: attr.Use = XmlSchemaUse.None; break; } restriction.Attributes.Add(attr); }
static XmlSchemaType AddElementTypeToXmlSchema(IUxmlFactory factory, SchemaInfo schemaInfo, FactoryProcessingHelper processingData) { // We always have complex types with complex content. XmlSchemaComplexType elementType = new XmlSchemaComplexType(); elementType.Name = factory.uxmlName + k_TypeSuffix; XmlSchemaComplexContent content = new XmlSchemaComplexContent(); elementType.ContentModel = content; // We only support restrictions of base types. XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction(); content.Content = restriction; if (factory.substituteForTypeName == String.Empty) { restriction.BaseTypeName = new XmlQualifiedName("anyType", k_XmlSchemaNamespace); } else { restriction.BaseTypeName = new XmlQualifiedName(factory.substituteForTypeName + k_TypeSuffix, factory.substituteForTypeNamespace); schemaInfo.importNamespaces.Add(factory.substituteForTypeNamespace); } if (factory.canHaveAnyAttribute) { XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute(); anyAttribute.ProcessContents = XmlSchemaContentProcessing.Lax; restriction.AnyAttribute = anyAttribute; } foreach (UxmlAttributeDescription attrDesc in factory.uxmlAttributesDescription) { XmlQualifiedName typeName = AddAttributeTypeToXmlSchema(schemaInfo, attrDesc, factory, processingData); if (typeName != null) { AddAttributeToXmlSchema(restriction, attrDesc, typeName); schemaInfo.importNamespaces.Add(attrDesc.typeNamespace); } } bool hasChildElements = false; foreach (UxmlChildElementDescription childDesc in factory.uxmlChildElementsDescription) { hasChildElements = true; schemaInfo.importNamespaces.Add(childDesc.elementNamespace); } if (hasChildElements) { restriction.Particle = MakeChoiceSequence(factory.uxmlChildElementsDescription); } schemaInfo.schema.Items.Add(elementType); return(elementType); }
public override void Check(ConformanceCheckContext ctx, XmlSchemaComplexContentRestriction 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); } }
private static void Equal(XmlSchemaComplexContentRestriction expected, XmlSchemaComplexContentRestriction actual) { AnnotatedEqual(expected, actual); Assert.Equal(expected.BaseTypeName, actual.BaseTypeName); IsEquivalentTo(expected.Particle, actual.Particle); IsEquivalentTo(expected.Attributes, actual.Attributes); IsEquivalentTo(expected.AnyAttribute, actual.AnyAttribute); }
private XmlSchemaContent Copy(XmlSchemaContent content) { XmlSchemaComplexContentExtension extension = content as XmlSchemaComplexContentExtension; XmlSchemaComplexContentRestriction restriction = content as XmlSchemaComplexContentRestriction; if (extension != null) { XmlSchemaComplexContentExtension newExtension = new XmlSchemaComplexContentExtension(); if (extension.BaseTypeName != null) { CopyDataType(extension.BaseTypeName.Name); newExtension.BaseTypeName = new XmlQualifiedName(extension.BaseTypeName.Name, this.ns); } if (extension.Particle != null) { XmlSchemaParticle newParticle = Copy(extension.Particle); newExtension.Particle = newParticle; } foreach (var attribute in extension.Attributes.Cast <XmlSchemaAttribute>()) { XmlSchemaAttribute newAttribute = this.Copy(attribute); newExtension.Attributes.Add(newAttribute); } return(newExtension); } if (restriction != null) { XmlSchemaComplexContentRestriction newRestriction = new XmlSchemaComplexContentRestriction(); if (restriction.BaseTypeName != null) { CopyDataType(restriction.BaseTypeName.Name); newRestriction.BaseTypeName = new XmlQualifiedName(restriction.BaseTypeName.Name, this.ns); } if (restriction.Particle != null) { XmlSchemaParticle newParticle = Copy(restriction.Particle); newRestriction.Particle = newParticle; } foreach (var attribute in restriction.Attributes.Cast <XmlSchemaAttribute>()) { XmlSchemaAttribute newAttribute = this.Copy(attribute); newRestriction.Attributes.Add(newAttribute); } return(newRestriction); } throw new Exception("Unexpected XmlSchemaComplexContent type (not extension or restriction)"); }
XmlQualifiedName ExportArrayMapping(ArrayMapping mapping, string ns) { // for the Rpc ArrayMapping different mappings could have the same schema type // we link all mappings corresponding to the same type together // loop through all mapping that will map to the same complexType, and export only one, // the obvious choice is the last one. while (mapping.Next != null) { mapping = mapping.Next; } XmlSchemaComplexType type = (XmlSchemaComplexType)types[mapping]; if (type == null) { CheckForDuplicateType(mapping.TypeName, mapping.Namespace); type = new XmlSchemaComplexType(); type.Name = mapping.TypeName; types.Add(mapping, type); // we need to add the type first, to make sure that the schema get created AddSchemaItem(type, mapping.Namespace, ns); AddSchemaImport(Soap.Encoding, mapping.Namespace); AddSchemaImport(Wsdl.Namespace, mapping.Namespace); XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction(); XmlQualifiedName qname = ExportTypeMapping(mapping.Elements[0].Mapping, mapping.Namespace); if (qname.IsEmpty) { // this is a root mapping qname = new XmlQualifiedName(Soap.UrType, XmlSchema.Namespace); } //<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:float[]"/> XmlSchemaAttribute attr = new XmlSchemaAttribute(); attr.RefName = ArrayTypeQName; XmlAttribute attribute = new XmlAttribute("wsdl", Wsdl.ArrayType, Wsdl.Namespace, Document); attribute.Value = qname.Namespace + ":" + qname.Name + "[]"; attr.UnhandledAttributes = new XmlAttribute[] { attribute }; restriction.Attributes.Add(attr); restriction.BaseTypeName = ArrayQName; XmlSchemaComplexContent model = new XmlSchemaComplexContent(); model.Content = restriction; type.ContentModel = model; if (qname.Namespace != XmlSchema.Namespace) { AddSchemaImport(qname.Namespace, mapping.Namespace); } } else { AddSchemaImport(mapping.Namespace, ns); } return(new XmlQualifiedName(mapping.TypeName, mapping.Namespace)); }
public static void ObtenerTipoDeDatoDerivadoDeXbrl(XmlSchema esquema, XmlSchemaType dataType, out XmlSchemaType dataTypeBaseQName) { dataTypeBaseQName = null; if (dataType.QualifiedName != null && dataType.QualifiedName.Namespace.Equals(EspacioNombresConstantes.InstanceNamespace)) { if (TiposDatoXBRL.TiposXBRL.Contains(dataType.QualifiedName.Name)) { dataTypeBaseQName = dataType; } } else { if (dataType.DerivedBy.Equals(XmlSchemaDerivationMethod.Restriction)) { XmlQualifiedName qName = null; if (dataType.GetType() == typeof(XmlSchemaSimpleType)) { XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)dataType; XmlSchemaSimpleTypeRestriction simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)simpleType.Content; qName = simpleTypeRestriction.BaseTypeName; } else if (dataType.GetType() == typeof(XmlSchemaComplexType)) { XmlSchemaComplexType complexType = (XmlSchemaComplexType)dataType; if (complexType.ContentModel == null) { ; } else { if (complexType.ContentModel.Content.GetType() == typeof(XmlSchemaComplexContentRestriction)) { XmlSchemaComplexContentRestriction content = (XmlSchemaComplexContentRestriction)complexType.ContentModel.Content; qName = content.BaseTypeName; } else { XmlSchemaSimpleContentRestriction content = (XmlSchemaSimpleContentRestriction)complexType.ContentModel.Content; qName = content.BaseTypeName; } } } if (qName != null) { XmlSchemaType tipo = esquema.SchemaTypes.Contains(qName) ? esquema.SchemaTypes[qName] as XmlSchemaType : null; if (tipo != null) { ObtenerTipoDeDatoDerivadoDeXbrl(esquema, tipo, out dataTypeBaseQName); } } } } }
void GetAttributeCompletionData(XmlCompletionDataList data, XmlSchemaComplexContentRestriction restriction) { GetAttributeCompletionData(data, restriction.Attributes); var baseComplexType = FindNamedType(schema, restriction.BaseTypeName); if (baseComplexType != null) { GetAttributeCompletionData(data, baseComplexType); } }
static void AddAppSequenceType(DiscoveryVersion discoveryVersion, XmlSchema schema) { //<xs:complexType name="AppSequenceType" > XmlSchemaComplexType appSequenceType = new XmlSchemaComplexType(); appSequenceType.Name = ProtocolStrings.SchemaNames.AppSequenceType; // <xs:complexContent> XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent(); appSequenceType.ContentModel = complexContent; // <xs:restriction base="xs:anyType" > XmlSchemaComplexContentRestriction contentRestriction = new XmlSchemaComplexContentRestriction(); complexContent.Content = contentRestriction; contentRestriction.BaseTypeName = discoveryVersion.Implementation.QualifiedNames.AnyType; // <xs:attribute name="InstanceId" type="xs:unsignedInt" use="required" /> XmlSchemaAttribute instanceId = new XmlSchemaAttribute(); instanceId.Name = ProtocolStrings.SchemaNames.AppSequenceInstanceId; instanceId.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.UnsignedIntType; instanceId.Use = XmlSchemaUse.Required; // <xs:attribute name="SequenceId" type="xs:anyURI" /> XmlSchemaAttribute sequenceId = new XmlSchemaAttribute(); sequenceId.Name = ProtocolStrings.SchemaNames.AppSequenceSequenceId; sequenceId.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.AnyUriType; // <xs:attribute name="MessageNumber" type="xs:unsignedInt" use="required" /> XmlSchemaAttribute messageNumber = new XmlSchemaAttribute(); messageNumber.Name = ProtocolStrings.SchemaNames.AppSequenceMessageNumber; messageNumber.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.UnsignedIntType; messageNumber.Use = XmlSchemaUse.Required; // <xs:anyAttribute namespace="##other" processContents="lax" /> XmlSchemaAnyAttribute anyAttribue = new XmlSchemaAnyAttribute(); anyAttribue.Namespace = "##other"; anyAttribue.ProcessContents = XmlSchemaContentProcessing.Lax; contentRestriction.Attributes.Add(instanceId); contentRestriction.Attributes.Add(sequenceId); contentRestriction.Attributes.Add(messageNumber); contentRestriction.AnyAttribute = anyAttribue; schema.Items.Add(appSequenceType); }
protected virtual void Visit(XmlSchemaComplexContentRestriction restriction) { if (restriction.Particle != null) { Traverse(restriction.Particle); } Traverse(restriction.Attributes); if (restriction.AnyAttribute != null) { Traverse(restriction.AnyAttribute); } }
void ParseArrayType(XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype) { XmlSchemaAttribute arrayTypeAt = FindArrayAttribute(rest.Attributes); XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes; if (uatts == null || uatts.Length == 0) { throw new InvalidOperationException("arrayType attribute not specified in array declaration"); } XmlAttribute xat = null; foreach (XmlAttribute at in uatts) { if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace) { xat = at; break; } } if (xat == null) { throw new InvalidOperationException("arrayType attribute not specified in array declaration"); } string arrayType = xat.Value; string type, ns; int i = arrayType.LastIndexOf(":"); if (i == -1) { ns = ""; } else { ns = arrayType.Substring(0, i); } int j = arrayType.IndexOf("[", i + 1); if (j == -1) { throw new InvalidOperationException("Cannot parse WSDL array type: " + arrayType); } type = arrayType.Substring(i + 1); type = type.Substring(0, type.Length - 2); qtype = new XmlQualifiedName(type, ns); }
void Parse_ComplexContent(TreeNode inner, string ns, XmlSchemaComplexContent content) { XmlQualifiedName qname; XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension; if (ext != null) { qname = ext.BaseTypeName; } else { XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content; qname = rest.BaseTypeName; if (qname == arrayType) { Parse_ArrayType(rest, out qname); XmlSchemaElement elem = new XmlSchemaElement(); elem.Name = "Item"; elem.SchemaTypeName = qname; TreeNode node = new TreeNode("arrayType" + SoapEncodingNamespace + qname.Name + "[2]"); inner.Nodes.Add(node); Add_Item(inner, ns, elem, true); return; } } // Add base map members to this map XmlSchemaComplexType ctype = GetComplexTypeByName(qname); Add_ComplexAttributes(inner, ctype); //Add base content first Add_ComplexElements(inner, ns, ctype); if (ext != null) { // Add the members of this map Add_Attributes(inner, ext.Attributes, ext.AnyAttribute); if (ext.Particle != null) { Parse_ParticleComplexContent(inner, ns, ext.Particle); } } }
private XmlQualifiedName ExportArrayMapping(ArrayMapping mapping, string ns) { while (mapping.Next != null) { mapping = mapping.Next; } if (((XmlSchemaComplexType)this.types[mapping]) == null) { this.CheckForDuplicateType(mapping.TypeName, mapping.Namespace); XmlSchemaComplexType type = new XmlSchemaComplexType { Name = mapping.TypeName }; this.types.Add(mapping, type); this.AddSchemaItem(type, mapping.Namespace, ns); this.AddSchemaImport("http://schemas.xmlsoap.org/soap/encoding/", mapping.Namespace); this.AddSchemaImport("http://schemas.xmlsoap.org/wsdl/", mapping.Namespace); XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction(); XmlQualifiedName name = this.ExportTypeMapping(mapping.Elements[0].Mapping, mapping.Namespace); if (name.IsEmpty) { name = new XmlQualifiedName("anyType", "http://www.w3.org/2001/XMLSchema"); } XmlSchemaAttribute item = new XmlSchemaAttribute { RefName = ArrayTypeQName }; XmlAttribute attribute2 = new XmlAttribute("wsdl", "arrayType", "http://schemas.xmlsoap.org/wsdl/", this.Document) { Value = name.Namespace + ":" + name.Name + "[]" }; item.UnhandledAttributes = new XmlAttribute[] { attribute2 }; restriction.Attributes.Add(item); restriction.BaseTypeName = ArrayQName; XmlSchemaComplexContent content = new XmlSchemaComplexContent { Content = restriction }; type.ContentModel = content; if (name.Namespace != "http://www.w3.org/2001/XMLSchema") { this.AddSchemaImport(name.Namespace, mapping.Namespace); } } else { this.AddSchemaImport(mapping.Namespace, ns); } return(new XmlQualifiedName(mapping.TypeName, mapping.Namespace)); }
public void GetExpectedValues(XmlSchemaType si, XmlIntellisenseList list) { if (si == null) { return; } if (si is XmlSchemaSimpleType) { XmlSchemaSimpleType st = (XmlSchemaSimpleType)si; GetExpectedValues(st, list); } else if (si is XmlSchemaComplexType) { XmlSchemaComplexType ct = (XmlSchemaComplexType)si; if (ct.ContentModel is XmlSchemaComplexContent) { XmlSchemaComplexContent cc = (XmlSchemaComplexContent)ct.ContentModel; if (cc.Content is XmlSchemaComplexContentExtension) { XmlSchemaComplexContentExtension ce = (XmlSchemaComplexContentExtension)cc.Content; GetExpectedValues(GetTypeInfo(ce.BaseTypeName), list); } else if (cc.Content is XmlSchemaComplexContentRestriction) { XmlSchemaComplexContentRestriction cr = (XmlSchemaComplexContentRestriction)cc.Content; GetExpectedValues(GetTypeInfo(cr.BaseTypeName), list); } } else if (ct.ContentModel is XmlSchemaSimpleContent) { XmlSchemaSimpleContent sc = (XmlSchemaSimpleContent)ct.ContentModel; if (sc.Content is XmlSchemaSimpleContentExtension) { XmlSchemaSimpleContentExtension ce = (XmlSchemaSimpleContentExtension)sc.Content; GetExpectedValues(GetTypeInfo(ce.BaseTypeName), list); } else if (sc.Content is XmlSchemaSimpleContentRestriction) { XmlSchemaSimpleContentRestriction cr = (XmlSchemaSimpleContentRestriction)sc.Content; GetExpectedValues(GetTypeInfo(cr.BaseTypeName), list); } } } return; }
XmlSchemaAttribute FindAttribute(XmlSchemaComplexContentRestriction restriction, string name) { var matchedAttribute = FindAttribute(restriction.Attributes, name); if (matchedAttribute != null) { return(matchedAttribute); } var complexType = FindNamedType(schema, restriction.BaseTypeName); if (complexType != null) { return(FindAttribute(complexType, name)); } return(null); }
/// <summary> /// Finds the named child element contained in the restriction element. /// </summary> XmlSchemaElement FindChildElement(XmlSchemaComplexContentRestriction restriction, QualifiedName name) { var sequence = restriction.Particle as XmlSchemaSequence; if (sequence != null) { return(FindElement(sequence.Items, name)); } var groupRef = restriction.Particle as XmlSchemaGroupRef; if (groupRef != null) { return(FindElement(groupRef, name)); } return(null); }
void WriteComplexContent(XmlTextWriter xtw, string ns, XmlSchemaComplexContent content) { XmlQualifiedName qname; XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension; if (ext != null) { qname = ext.BaseTypeName; } else { XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content; qname = rest.BaseTypeName; if (qname == arrayType) { ParseArrayType(rest, out qname); XmlSchemaElement elem = new XmlSchemaElement(); elem.Name = "Item"; elem.SchemaTypeName = qname; xtw.WriteAttributeString("arrayType", SoapEncodingNamespace, qname.Name + "[2]"); WriteContentItem(xtw, ns, elem, true); return; } } // Add base map members to this map XmlSchemaComplexType ctype = FindComplexTyype(qname); WriteComplexTypeAttributes(xtw, ctype); if (ext != null) { // Add the members of this map WriteAttributes(xtw, ext.Attributes, ext.AnyAttribute); if (ext.Particle != null) { WriteParticleComplexContent(xtw, ns, ext.Particle); } } WriteComplexTypeElements(xtw, ns, ctype); }
XmlSchemaComplexType GetComplexTypeByName(XmlQualifiedName qname) { if (qname.Name.IndexOf("[]") != -1) { XmlSchemaComplexType stype = new XmlSchemaComplexType(); stype.ContentModel = new XmlSchemaComplexContent(); XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction(); stype.ContentModel.Content = res; res.BaseTypeName = arrayType; XmlSchemaAttribute att = new XmlSchemaAttribute(); att.RefName = arrayTypeRefName; res.Attributes.Add(att); return(stype); } return((XmlSchemaComplexType)_schemas.Find(qname, typeof(XmlSchemaComplexType))); }
XmlSchemaComplexType FindComplexTyype(XmlQualifiedName qname) { if (qname.Name.IndexOf("[]") != -1) { XmlSchemaComplexType stype = new XmlSchemaComplexType(); stype.ContentModel = new XmlSchemaComplexContent(); XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction(); stype.ContentModel.Content = res; res.BaseTypeName = arrayType; XmlSchemaAttribute att = new XmlSchemaAttribute(); att.RefName = arrayTypeRefName; res.Attributes.Add(att); XmlAttribute xat = document.CreateAttribute("arrayType", WsdlNamespace); xat.Value = qname.Namespace + ":" + qname.Name; att.UnhandledAttributes = new XmlAttribute[] { xat }; return(stype); } return((XmlSchemaComplexType)schemas.Find(qname, typeof(XmlSchemaComplexType))); }
void Write56_XmlSchemaComplexContentRestriction(XmlSchemaComplexContentRestriction o) { if ((object)o == null) { return; } WriteStartElement("restriction"); 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(); }
public static void Main() { XmlSchema schema = new XmlSchema(); // <xs:complexType name="phoneNumber"> XmlSchemaComplexType phoneNumber = new XmlSchemaComplexType(); phoneNumber.Name = "phoneNumber"; // <xs:sequence> XmlSchemaSequence phoneNumberSequence = new XmlSchemaSequence(); // <xs:element name="areaCode"/> XmlSchemaElement areaCode1 = new XmlSchemaElement(); areaCode1.MinOccurs = 0; areaCode1.MaxOccursString = "1"; areaCode1.Name = "areaCode"; phoneNumberSequence.Items.Add(areaCode1); // <xs:element name="prefix"/> XmlSchemaElement prefix1 = new XmlSchemaElement(); prefix1.MinOccurs = 1; prefix1.MaxOccursString = "1"; prefix1.Name = "prefix"; phoneNumberSequence.Items.Add(prefix1); // <xs:element name="number"/> XmlSchemaElement number1 = new XmlSchemaElement(); number1.MinOccurs = 1; number1.MaxOccursString = "1"; number1.Name = "number"; phoneNumberSequence.Items.Add(number1); phoneNumber.Particle = phoneNumberSequence; schema.Items.Add(phoneNumber); // <xs:complexType name="localPhoneNumber"> XmlSchemaComplexType localPhoneNumber = new XmlSchemaComplexType(); localPhoneNumber.Name = "localPhoneNumber"; // <xs:complexContent> XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent(); // <xs:restriction base="phoneNumber"> XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction(); restriction.BaseTypeName = new XmlQualifiedName("phoneNumber", ""); // <xs:sequence> XmlSchemaSequence sequence2 = new XmlSchemaSequence(); // <xs:element name="areaCode" minOccurs="0"/> XmlSchemaElement areaCode2 = new XmlSchemaElement(); areaCode2.MinOccurs = 0; areaCode2.MaxOccursString = "1"; areaCode2.Name = "areaCode"; sequence2.Items.Add(areaCode2); // <xs:element name="prefix"/> XmlSchemaElement prefix2 = new XmlSchemaElement(); prefix2.MinOccurs = 1; prefix2.MaxOccursString = "1"; prefix2.Name = "prefix"; sequence2.Items.Add(prefix2); // <xs:element name="number"/> XmlSchemaElement number2 = new XmlSchemaElement(); number2.MinOccurs = 1; number2.MaxOccursString = "1"; number2.Name = "number"; sequence2.Items.Add(number2); restriction.Particle = sequence2; complexContent.Content = restriction; localPhoneNumber.ContentModel = complexContent; schema.Items.Add(localPhoneNumber); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne); schemaSet.Add(schema); schemaSet.Compile(); XmlSchema compiledSchema = null; foreach (XmlSchema schema1 in schemaSet.Schemas()) { compiledSchema = schema1; } XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); compiledSchema.Write(Console.Out, nsmgr); }
XmlQualifiedName ExportArraySchema(XmlTypeMapping map, string defaultNamespace) { ListMap lmap = (ListMap)map.ObjectMap; if (encodedFormat) { string name, ns, schemaNs; lmap.GetArrayType(-1, out name, out ns); if (ns == XmlSchema.Namespace) { schemaNs = defaultNamespace; } else { schemaNs = ns; } if (IsMapExported(map)) { return(new XmlQualifiedName(lmap.GetSchemaArrayName(), schemaNs)); } SetMapExported(map); XmlSchema schema = GetSchema(schemaNs); XmlSchemaComplexType stype = new XmlSchemaComplexType(); stype.Name = lmap.GetSchemaArrayName(); schema.Items.Add(stype); XmlSchemaComplexContent content = new XmlSchemaComplexContent(); content.IsMixed = false; stype.ContentModel = content; XmlSchemaComplexContentRestriction rest = new XmlSchemaComplexContentRestriction(); content.Content = rest; rest.BaseTypeName = new XmlQualifiedName("Array", XmlSerializer.EncodingNamespace); XmlSchemaAttribute at = new XmlSchemaAttribute(); rest.Attributes.Add(at); at.RefName = new XmlQualifiedName("arrayType", XmlSerializer.EncodingNamespace); XmlAttribute arrayType = Document.CreateAttribute("arrayType", XmlSerializer.WsdlNamespace); arrayType.Value = ns + (ns != "" ? ":" : "") + name; at.UnhandledAttributes = new XmlAttribute [] { arrayType }; ImportNamespace(schema, XmlSerializer.WsdlNamespace); XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo)lmap.ItemInfo[0]; if (einfo.MappedType != null) { switch (einfo.TypeData.SchemaType) { case SchemaTypes.Enum: ExportEnumSchema(einfo.MappedType); break; case SchemaTypes.Array: ExportArraySchema(einfo.MappedType, schemaNs); break; case SchemaTypes.Class: ExportClassSchema(einfo.MappedType); break; } } return(new XmlQualifiedName(lmap.GetSchemaArrayName(), schemaNs)); } else { if (IsMapExported(map)) { return(new XmlQualifiedName(map.XmlType, map.XmlTypeNamespace)); } SetMapExported(map); XmlSchema schema = GetSchema(map.XmlTypeNamespace); XmlSchemaComplexType stype = new XmlSchemaComplexType(); stype.Name = map.ElementName; schema.Items.Add(stype); XmlSchemaParticle spart = GetSchemaArrayElement(schema, lmap.ItemInfo); if (spart is XmlSchemaChoice) { stype.Particle = spart; } else { XmlSchemaSequence seq = new XmlSchemaSequence(); seq.Items.Add(spart); stype.Particle = seq; } return(new XmlQualifiedName(map.XmlType, map.XmlTypeNamespace)); } }
private ArrayMapping ImportArrayMapping(XmlSchemaType type, string ns) { ArrayMapping arrayMapping; if (type.Name == Soap.Array && ns == Soap.Encoding) { arrayMapping = new ArrayMapping(); TypeMapping mapping = GetRootMapping(); ElementAccessor itemAccessor = new ElementAccessor(); itemAccessor.IsSoap = true; itemAccessor.Name = Soap.UrType; itemAccessor.Namespace = ns; itemAccessor.Mapping = mapping; itemAccessor.IsNullable = true; itemAccessor.Form = XmlSchemaForm.None; arrayMapping.Elements = new ElementAccessor[] { itemAccessor }; arrayMapping.TypeDesc = itemAccessor.Mapping.TypeDesc.CreateArrayTypeDesc(); arrayMapping.TypeName = "ArrayOf" + CodeIdentifier.MakePascal(itemAccessor.Mapping.TypeName); return(arrayMapping); } if (!(type.DerivedFrom.Name == Soap.Array && type.DerivedFrom.Namespace == Soap.Encoding)) { return(null); } // the type should be a XmlSchemaComplexType XmlSchemaContentModel model = ((XmlSchemaComplexType)type).ContentModel; // the Content should be an restriction if (!(model.Content is XmlSchemaComplexContentRestriction)) { return(null); } arrayMapping = new ArrayMapping(); XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction)model.Content; for (int i = 0; i < restriction.Attributes.Count; i++) { XmlSchemaAttribute attribute = restriction.Attributes[i] as XmlSchemaAttribute; if (attribute != null && attribute.RefName.Name == Soap.ArrayType && attribute.RefName.Namespace == Soap.Encoding) { // read the value of the wsdl:arrayType attribute string arrayType = null; if (attribute.UnhandledAttributes != null) { foreach (XmlAttribute a in attribute.UnhandledAttributes) { if (a.LocalName == Wsdl.ArrayType && a.NamespaceURI == Wsdl.Namespace) { arrayType = a.Value; break; } } } if (arrayType != null) { string dims; XmlQualifiedName typeName = TypeScope.ParseWsdlArrayType(arrayType, out dims, attribute); TypeMapping mapping; TypeDesc td = Scope.GetTypeDesc(typeName.Name, typeName.Namespace); if (td != null && td.IsPrimitive) { mapping = new PrimitiveMapping(); mapping.TypeDesc = td; mapping.TypeName = td.DataType.Name; } else { mapping = ImportType(typeName, false); } ElementAccessor itemAccessor = new ElementAccessor(); itemAccessor.IsSoap = true; itemAccessor.Name = typeName.Name; itemAccessor.Namespace = ns; itemAccessor.Mapping = mapping; itemAccessor.IsNullable = true; itemAccessor.Form = XmlSchemaForm.None; arrayMapping.Elements = new ElementAccessor[] { itemAccessor }; arrayMapping.TypeDesc = itemAccessor.Mapping.TypeDesc.CreateArrayTypeDesc(); arrayMapping.TypeName = "ArrayOf" + CodeIdentifier.MakePascal(itemAccessor.Mapping.TypeName); return(arrayMapping); } } } XmlSchemaParticle particle = restriction.Particle; if (particle is XmlSchemaAll || particle is XmlSchemaSequence) { XmlSchemaGroupBase group = (XmlSchemaGroupBase)particle; if (group.Items.Count != 1 || !(group.Items[0] is XmlSchemaElement)) { return(null); } XmlSchemaElement itemElement = (XmlSchemaElement)group.Items[0]; if (!itemElement.IsMultipleOccurrence) { return(null); } ElementAccessor itemAccessor = ImportElement(itemElement, ns); arrayMapping.Elements = new ElementAccessor[] { itemAccessor }; arrayMapping.TypeDesc = ((TypeMapping)itemAccessor.Mapping).TypeDesc.CreateArrayTypeDesc(); } else { return(null); } return(arrayMapping); }
static void Check(ConformanceCheckContext ctx, ConformanceChecker checker, Hashtable visitedObjects, XmlSchemaObject value) { if (value == null) { return; } if (visitedObjects.Contains(value)) { return; } visitedObjects.Add(value, value); if (value is XmlSchemaImport) { XmlSchemaImport so = (XmlSchemaImport)value; checker.Check(ctx, so); } else if (value is XmlSchemaAll) { XmlSchemaAll so = (XmlSchemaAll)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Items); } else if (value is XmlSchemaAnnotation) { XmlSchemaAnnotation so = (XmlSchemaAnnotation)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Items); } else if (value is XmlSchemaAttribute) { XmlSchemaAttribute so = (XmlSchemaAttribute)value; checker.Check(ctx, so); } else if (value is XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup so = (XmlSchemaAttributeGroup)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Attributes); Check(ctx, checker, visitedObjects, so.AnyAttribute); Check(ctx, checker, visitedObjects, so.RedefinedAttributeGroup); } else if (value is XmlSchemaAttributeGroupRef) { XmlSchemaAttributeGroupRef so = (XmlSchemaAttributeGroupRef)value; checker.Check(ctx, so); } else if (value is XmlSchemaChoice) { XmlSchemaChoice so = (XmlSchemaChoice)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Items); } else if (value is XmlSchemaComplexContent) { XmlSchemaComplexContent so = (XmlSchemaComplexContent)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.Content); } else if (value is XmlSchemaComplexContentExtension) { XmlSchemaComplexContentExtension so = (XmlSchemaComplexContentExtension)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.Particle); CheckObjects(ctx, checker, visitedObjects, so.Attributes); Check(ctx, checker, visitedObjects, so.AnyAttribute); } else if (value is XmlSchemaComplexContentRestriction) { XmlSchemaComplexContentRestriction so = (XmlSchemaComplexContentRestriction)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.Particle); CheckObjects(ctx, checker, visitedObjects, so.Attributes); Check(ctx, checker, visitedObjects, so.AnyAttribute); } else if (value is XmlSchemaComplexType) { XmlSchemaComplexType so = (XmlSchemaComplexType)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.ContentModel); Check(ctx, checker, visitedObjects, so.Particle); CheckObjects(ctx, checker, visitedObjects, so.Attributes); Check(ctx, checker, visitedObjects, so.AnyAttribute); Check(ctx, checker, visitedObjects, so.ContentTypeParticle); Check(ctx, checker, visitedObjects, so.AttributeWildcard); } else if (value is XmlSchemaElement) { XmlSchemaElement so = (XmlSchemaElement)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.SchemaType); CheckObjects(ctx, checker, visitedObjects, so.Constraints); } else if (value is XmlSchemaGroup) { XmlSchemaGroup so = (XmlSchemaGroup)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.Particle); } else if (value is XmlSchemaGroupRef) { XmlSchemaGroupRef so = (XmlSchemaGroupRef)value; checker.Check(ctx, so); } else if (value is XmlSchemaIdentityConstraint) { XmlSchemaIdentityConstraint so = (XmlSchemaIdentityConstraint)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Fields); Check(ctx, checker, visitedObjects, so.Selector); } else if (value is XmlSchemaKeyref) { XmlSchemaKeyref so = (XmlSchemaKeyref)value; checker.Check(ctx, so); } else if (value is XmlSchemaRedefine) { XmlSchemaRedefine so = (XmlSchemaRedefine)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Items); } else if (value is XmlSchemaSequence) { XmlSchemaSequence so = (XmlSchemaSequence)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Items); } else if (value is XmlSchemaSimpleContent) { XmlSchemaSimpleContent so = (XmlSchemaSimpleContent)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.Content); } else if (value is XmlSchemaSimpleContentExtension) { XmlSchemaSimpleContentExtension so = (XmlSchemaSimpleContentExtension)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Attributes); Check(ctx, checker, visitedObjects, so.AnyAttribute); } else if (value is XmlSchemaSimpleContentRestriction) { XmlSchemaSimpleContentRestriction so = (XmlSchemaSimpleContentRestriction)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Attributes); Check(ctx, checker, visitedObjects, so.AnyAttribute); CheckObjects(ctx, checker, visitedObjects, so.Facets); } else if (value is XmlSchemaSimpleType) { XmlSchemaSimpleType so = (XmlSchemaSimpleType)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.Content); } else if (value is XmlSchemaSimpleTypeList) { XmlSchemaSimpleTypeList so = (XmlSchemaSimpleTypeList)value; checker.Check(ctx, so); } else if (value is XmlSchemaSimpleTypeRestriction) { XmlSchemaSimpleTypeRestriction so = (XmlSchemaSimpleTypeRestriction)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Facets); } else if (value is XmlSchemaSimpleTypeUnion) { XmlSchemaSimpleTypeUnion so = (XmlSchemaSimpleTypeUnion)value; checker.Check(ctx, so); } }
protected override void Visit(XmlSchemaComplexContentRestriction restriction) { ProcessRestriction(restriction.BaseTypeName, restriction.Attributes, restriction.AnyAttribute); }