/// <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("Separator", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional)); 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); }
/// <summary> /// Creates the schema type representing the body of the node type /// </summary> /// <returns>Type definition for a node</returns> static XmlSchemaType CreateNodeBodyType(Dictionary <string, XmlSchemaComplexType> TaskNameToType) { XmlSchemaChoice NodeChoice = new XmlSchemaChoice(); NodeChoice.MinOccurs = 0; NodeChoice.MaxOccursString = "unbounded"; NodeChoice.Items.Add(CreateSchemaElement("Property", ScriptSchemaStandardType.Property)); NodeChoice.Items.Add(CreateSchemaElement("EnvVar", ScriptSchemaStandardType.EnvVar)); NodeChoice.Items.Add(CreateSchemaElement("Warning", ScriptSchemaStandardType.Warning)); NodeChoice.Items.Add(CreateSchemaElement("Error", ScriptSchemaStandardType.Error)); NodeChoice.Items.Add(CreateDoElement(ScriptSchemaStandardType.NodeBody)); NodeChoice.Items.Add(CreateSwitchElement(ScriptSchemaStandardType.NodeBody)); NodeChoice.Items.Add(CreateForEachElement(ScriptSchemaStandardType.NodeBody)); foreach (KeyValuePair <string, XmlSchemaComplexType> Pair in TaskNameToType.OrderBy(x => x.Key)) { NodeChoice.Items.Add(CreateSchemaElement(Pair.Key, new XmlQualifiedName(Pair.Value.Name, NamespaceURI))); } XmlSchemaComplexType NodeType = new XmlSchemaComplexType(); NodeType.Name = GetTypeName(ScriptSchemaStandardType.NodeBody); NodeType.Particle = NodeChoice; return(NodeType); }
public void TestReadTypedAttributeValue() { string xml = "<root attr='12'></root>"; XmlSchema schema = new XmlSchema(); XmlSchemaElement elem = new XmlSchemaElement(); elem.Name = "root"; XmlSchemaComplexType ct = new XmlSchemaComplexType(); XmlSchemaAttribute attr = new XmlSchemaAttribute(); attr.Name = "attr"; attr.SchemaTypeName = new XmlQualifiedName("int", XmlSchema.Namespace); ct.Attributes.Add(attr); elem.SchemaType = ct; schema.Items.Add(elem); xvr = PrepareXmlReader(xml); xvr.Schemas.Add(schema); xvr.Read(); Assert.AreEqual("root", xvr.Name); Assert.IsTrue(xvr.MoveToNextAttribute()); // attr Assert.AreEqual("attr", xvr.Name); XmlSchemaDatatype dt = xvr.SchemaType as XmlSchemaDatatype; Assert.IsNotNull(dt); Assert.AreEqual(typeof(int), dt.ValueType); Assert.AreEqual(XmlTokenizedType.None, dt.TokenizedType); object o = xvr.ReadTypedValue(); Assert.AreEqual(XmlNodeType.Attribute, xvr.NodeType); Assert.AreEqual(typeof(int), o.GetType()); int n = (int)o; Assert.AreEqual(12, n); Assert.IsTrue(xvr.ReadAttributeValue()); // can read = seems not proceed. }
private static XmlSchemaElement EqualSchema() { XmlSchemaComplexType type = new XmlSchemaComplexType(); XmlSchemaAttribute attrib = new XmlSchemaAttribute(); attrib.Name = "refValue"; attrib.Use = XmlSchemaUse.Required; attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); type.Attributes.Add(attrib); attrib = new XmlSchemaAttribute(); attrib.Name = "test"; attrib.Use = XmlSchemaUse.Optional; attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); type.Attributes.Add(attrib); attrib = new XmlSchemaAttribute(); attrib.Name = "expressionLanguage"; attrib.Use = XmlSchemaUse.Optional; attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); type.Attributes.Add(attrib); attrib = new XmlSchemaAttribute(); attrib.Name = "failMessage"; attrib.Use = XmlSchemaUse.Optional; attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); type.Attributes.Add(attrib); XmlSchemaElement element = new XmlSchemaElement(); element.Name = "equal"; element.SchemaType = type; return(element); }
private void ExportTypeMembers(XmlSchemaComplexType type, MemberMapping[] members, string ns) { XmlSchemaGroupBase seq = new XmlSchemaSequence(); for (int i = 0; i < members.Length; i++) { MemberMapping member = members[i]; if (member.Elements.Length > 0) { bool valueTypeOptional = member.CheckSpecified != SpecifiedAccessor.None || member.CheckShouldPersist || !member.TypeDesc.IsValueType; ExportElementAccessors(seq, member.Elements, false, valueTypeOptional, ns); } } if (seq.Items.Count > 0) { if (type.ContentModel != null) { if (type.ContentModel.Content is XmlSchemaComplexContentExtension) { ((XmlSchemaComplexContentExtension)type.ContentModel.Content).Particle = seq; } else if (type.ContentModel.Content is XmlSchemaComplexContentRestriction) { ((XmlSchemaComplexContentRestriction)type.ContentModel.Content).Particle = seq; } else { throw new InvalidOperationException(SR.Format(SR.XmlInvalidContent, type.ContentModel.Content.GetType().Name)); } } else { type.Particle = seq; } } }
private static XmlSchemaElement AnySchema() { XmlSchemaComplexType type = new XmlSchemaComplexType(); XmlSchemaAttribute attrib = new XmlSchemaAttribute(); attrib.Name = "expressionLanguage"; attrib.Use = XmlSchemaUse.Optional; attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); type.Attributes.Add(attrib); attrib = new XmlSchemaAttribute(); attrib.Name = "failMessage"; attrib.Use = XmlSchemaUse.Optional; attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); type.Attributes.Add(attrib); XmlSchemaAny any = new XmlSchemaAny(); any.MinOccurs = 1; any.MaxOccursString = "unbounded"; any.ProcessContents = XmlSchemaContentProcessing.Strict; any.Namespace = "##local"; XmlSchemaSequence sequence = new XmlSchemaSequence(); type.Particle = sequence; sequence.Items.Add(any); XmlSchemaElement element = new XmlSchemaElement(); element.Name = "any"; element.SchemaType = type; return(element); }
XmlSchemaComplexType CreateComplexType(QName qname, Type type) { var xs = GetSchema(qname.Namespace); var el = new XmlSchemaElement() { Name = qname.Name, IsNillable = true }; el.SchemaTypeName = qname; xs.Items.Add(el); var ct = new XmlSchemaComplexType() { Name = qname.Name }; xs.Items.Add(ct); imported_types.Add(new TypeImportInfo() { RootElementName = qname, SchemaType = ct, SchemaTypeName = qname, ClrType = type }); return(ct); }
private XmlSchemaGroupBase AddElement(Action <XmlSchemaElement> add, string name, bool required, bool multiple, XmlSchemaComplexType type = null) { var element = new XmlSchemaElement(); if (!required) { element.MinOccurs = 0; element.MaxOccursString = multiple ? "unbounded" : "1"; } else if (multiple) { element.MinOccurs = 1; element.MaxOccursString = "unbounded"; } XmlSchemaComplexType currentType = type == null ? new XmlSchemaComplexType() : type; var all = new XmlSchemaAll(); element.Name = name; if (type == null) { element.SchemaType = currentType; } else { element.SchemaTypeName = new XmlQualifiedName(currentType.Name); } currentType.Particle = all; add(element); return(all); }
} //WriteXmlSchemaAttribute() /// <summary> /// /// </summary> /// <param name="complexType"></param> /// <param name="myXmlSchema"></param> /// <param name="myXmlTextWriter"></param> public static void WriteXmlSchemaComplexType(XmlSchemaComplexType complexType, XmlSchema myXmlSchema, XmlTextWriter myXmlTextWriter) { myXmlTextWriter.WriteStartElement("complexType", XmlSchema.Namespace); if (complexType.Name != null) { myXmlTextWriter.WriteAttributeString("name", complexType.Name); } //if if (complexType.ContentModel != null) { Console.WriteLine("Not Implemented for this ContentModel."); } //if else { if (complexType.Particle != null) WriteXmlSchemaParticle(complexType.Particle, myXmlSchema, myXmlTextWriter); foreach(object o in complexType.Attributes) { if (o is XmlSchemaAttribute) WriteXmlSchemaAttribute((XmlSchemaAttribute)o, myXmlTextWriter); } //foreach } //else myXmlTextWriter.WriteEndElement(); } //WriteXmlSchemaComplexType()
void GenerateXmlSchema(String[] formats, String fileFormatType) { StreamWriter writer = File.CreateText(xmlSchemaFile + "_" + fileFormatType + ".xml"); XmlSchema schema; XmlSchemaElement element; XmlSchemaComplexType complexType; XmlSchemaSequence sequence; schema = new XmlSchema(); element = new XmlSchemaElement(); schema.Items.Add(element); element.Name = "Table"; complexType = new XmlSchemaComplexType(); element.SchemaType = complexType; sequence = new XmlSchemaSequence(); complexType.Particle = sequence; element = new XmlSchemaElement(); element.Name = "Number"; element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); sequence.Items.Add(element); for(int i=0; i<formats.Length; i++){ element = new XmlSchemaElement(); element.Name = formats[i]; element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); sequence.Items.Add(element); } schema.Compile(new ValidationEventHandler(ValidationCallbackOne)); schema.Write(writer); writer.Close(); }
private XmlSchemaGroupBase AddElement(XmlSchemaGroupBase schema, string name, bool required = true, bool multiple = false, XmlSchemaComplexType type = null) { return(AddElement(element => schema.Items.Add(element), name, required, multiple, type)); }
public static void Main() { XmlTextReader tr = new XmlTextReader("empty.xsd"); XmlSchema schema = XmlSchema.Read(tr, new ValidationEventHandler(ValidationCallback)); schema.ElementFormDefault = XmlSchemaForm.Qualified; schema.TargetNamespace = "http://www.example.com/Report"; { XmlSchemaElement element = new XmlSchemaElement(); element.Name = "purchaseReport"; XmlSchemaComplexType element_complexType = new XmlSchemaComplexType(); XmlSchemaSequence element_complexType_sequence = new XmlSchemaSequence(); { XmlSchemaElement element_complexType_sequence_element = new XmlSchemaElement(); element_complexType_sequence_element.Name = "region"; element_complexType_sequence_element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema") ; { XmlSchemaKeyref element_complexType_sequence_element_keyref = new XmlSchemaKeyref(); element_complexType_sequence_element_keyref.Name = "dummy2"; element_complexType_sequence_element_keyref.Selector = new XmlSchemaXPath(); element_complexType_sequence_element_keyref.Selector.XPath = "r:zip/r:part"; { XmlSchemaXPath field = new XmlSchemaXPath(); field.XPath = "@number"; element_complexType_sequence_element_keyref.Fields.Add(field); } element_complexType_sequence_element_keyref.Refer = new XmlQualifiedName("pNumKey", "http://www.example.com/Report") ; element_complexType_sequence_element.Constraints.Add(element_complexType_sequence_element_keyref); } element_complexType_sequence.Items.Add(element_complexType_sequence_element); } element_complexType.Particle = element_complexType_sequence; { XmlSchemaAttribute element_complexType_attribute = new XmlSchemaAttribute(); element_complexType_attribute.Name = "periodEnding"; element_complexType_attribute.SchemaTypeName = new XmlQualifiedName("date", "http://www.w3.org/2001/XMLSchema") ; element_complexType.Attributes.Add(element_complexType_attribute); } element.SchemaType = element_complexType; { XmlSchemaKey element_key = new XmlSchemaKey(); element_key.Name = "pNumKey"; element_key.Selector = new XmlSchemaXPath(); element_key.Selector.XPath = "r:parts/r:part"; { XmlSchemaXPath field = new XmlSchemaXPath(); field.XPath = "@number"; element_key.Fields.Add(field); } element.Constraints.Add(element_key); } schema.Items.Add(element); } schema.Write(Console.Out); }/* Main() */
public static XmlSchemaComplexType GetTypedTableSchema(XmlSchemaSet xs) { XmlSchemaComplexType type = new XmlSchemaComplexType(); XmlSchemaSequence sequence = new XmlSchemaSequence(); HaushaltsbuchDS ds = new HaushaltsbuchDS(); XmlSchemaAny any1 = new XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); XmlSchemaAny any2 = new XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); XmlSchemaAttribute attribute1 = new XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); XmlSchemaAttribute attribute2 = new XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "BuchungssatzDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { MemoryStream s1 = new MemoryStream(); MemoryStream s2 = new MemoryStream(); try { XmlSchema schema = null; dsSchema.Write(s1); for (IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
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); }
private void ExportCollectionDataContract(CollectionDataContract collectionDataContract, XmlSchema schema) { XmlSchemaComplexType type = new XmlSchemaComplexType(); type.Name = collectionDataContract.StableName.Name; schema.Items.Add(type); XmlElement genericInfoElement = null, isDictionaryElement = null; if (collectionDataContract.UnderlyingType.IsGenericType && CollectionDataContract.IsCollectionDataContract(collectionDataContract.UnderlyingType)) { genericInfoElement = ExportGenericInfo(collectionDataContract.UnderlyingType, Globals.GenericTypeLocalName, Globals.SerializationNamespace); } if (collectionDataContract.IsDictionary) { isDictionaryElement = ExportIsDictionary(); } type.Annotation = GetSchemaAnnotation(isDictionaryElement, genericInfoElement, ExportSurrogateData(collectionDataContract)); XmlSchemaSequence rootSequence = new XmlSchemaSequence(); XmlSchemaElement element = new XmlSchemaElement(); element.Name = collectionDataContract.ItemName; element.MinOccurs = 0; element.MaxOccursString = Globals.OccursUnbounded; if (collectionDataContract.IsDictionary) { ClassDataContract keyValueContract = collectionDataContract.ItemContract as ClassDataContract; XmlSchemaComplexType keyValueType = new XmlSchemaComplexType(); XmlSchemaSequence keyValueSequence = new XmlSchemaSequence(); foreach (DataMember dataMember in keyValueContract.Members) { XmlSchemaElement keyValueElement = new XmlSchemaElement(); keyValueElement.Name = dataMember.Name; SetElementType(keyValueElement, _dataContractSet.GetMemberTypeDataContract(dataMember), schema); SchemaHelper.AddElementForm(keyValueElement, schema); if (dataMember.IsNullable) { keyValueElement.IsNillable = true; } keyValueElement.Annotation = GetSchemaAnnotation(ExportSurrogateData(dataMember)); keyValueSequence.Items.Add(keyValueElement); } keyValueType.Particle = keyValueSequence; element.SchemaType = keyValueType; } else { if (collectionDataContract.IsItemTypeNullable) { element.IsNillable = true; } DataContract itemContract = _dataContractSet.GetItemTypeDataContract(collectionDataContract); SetElementType(element, itemContract, schema); } SchemaHelper.AddElementForm(element, schema); rootSequence.Items.Add(element); type.Particle = rootSequence; if (collectionDataContract.IsReference) { AddReferenceAttributes(type.Attributes, schema); } }
private void AddXMLProperties(XmlSchemaElement parent, XmlSchemaObjectCollection items, XmlSchemaObjectCollection attributes, PropertyInfo[] properties) { foreach (PropertyInfo property in properties) { if (IsValidProperty(property)) { string propertyName = property.Name; if (propertyName.Equals("Item") && property.DeclaringType.Name.StartsWith("List`")) { if (!parent.Name.Equals("Items")) { propertyName = StringUtils.ToSingular(parent.Name); } else { propertyName = property.PropertyType.Name; } } string xmlPropertyType = GetPropertyTypeName(property.PropertyType, TDataExchangeFormat.Xml); if (property.GetCustomAttributes <XmlAttributeAttribute>().FirstOrDefault() != null) { XmlSchemaAttribute attribute = new XmlSchemaAttribute(); attribute.Name = propertyName; attribute.SchemaTypeName = new XmlQualifiedName(xmlPropertyType, XML_NAMESPACE); if (attribute.Name.Equals("type")) { attribute.Use = XmlSchemaUse.Optional; } attributes.Add(attribute); } else { XmlSchemaElement propertyElement = new XmlSchemaElement(); propertyElement.Name = propertyName; if (xmlPropertyType.Equals("array") || xmlPropertyType.Equals("object")) { XmlSchemaComplexType complexType = new XmlSchemaComplexType(); propertyElement.SchemaType = complexType; XmlSchemaGroupBase sequence = null; if (xmlPropertyType.Equals("array")) { sequence = new XmlSchemaSequence(); sequence.MinOccursString = "0"; sequence.MaxOccursString = "unbounded"; if (parent != null) { // nested empty collections shouldn't have to exist. propertyElement.UnhandledAttributes = new XmlAttribute[1]; propertyElement.UnhandledAttributes[0] = new XmlDocument().CreateAttribute("minOccurs"); propertyElement.UnhandledAttributes[0].Value = "0"; } } else { sequence = new XmlSchemaAll(); } AddXMLProperties(propertyElement, sequence.Items, complexType.Attributes, property.PropertyType.GetProperties()); if (sequence.Items.Count > 0) { complexType.Particle = sequence; } } else { propertyElement.SchemaTypeName = new XmlQualifiedName(xmlPropertyType, XML_NAMESPACE); } items.Add(propertyElement); } } } }
public void DumpComplexType (XmlSchemaComplexType c) { depth++; IndentLine ("**ComplexType**"); IndentLine ("QualifiedName: " + c.QualifiedName); IndentLine ("ContentType: " + c.ContentType); IndentLine ("ContentTypeParticle: "); DumpParticle (c.ContentTypeParticle); IndentLine ("BaseSchemaType:"); DumpType (c.BaseSchemaType); depth--; }
private void WriteXMLForCultures(CultureInfo[] cultures) { StreamWriter writer = File.CreateText("CultureSchema.xml"); XmlSchema schema; XmlSchemaElement element; XmlSchemaComplexType complexType; XmlSchemaSequence sequence; schema = new XmlSchema(); element = new XmlSchemaElement(); schema.Items.Add(element); element.Name = "Table"; complexType = new XmlSchemaComplexType(); element.SchemaType = complexType; sequence = new XmlSchemaSequence(); complexType.Particle = sequence; element = new XmlSchemaElement(); element.Name = "CultureName"; element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); sequence.Items.Add(element); schema.Compile(new ValidationEventHandler(ValidationCallbackOne)); schema.Write(writer); writer.Close(); writer = File.CreateText("CultureData.xml"); XmlTextWriter myXmlTextWriter = new XmlTextWriter(writer); myXmlTextWriter.Formatting = Formatting.Indented; myXmlTextWriter.WriteStartElement("NewDataSet"); for(int j=0; j<cultures.Length; j++) { myXmlTextWriter.WriteStartElement("Table"); myXmlTextWriter.WriteElementString("CultureName", cultures[j].LCID.ToString()); myXmlTextWriter.WriteEndElement(); } myXmlTextWriter.WriteEndElement(); myXmlTextWriter.Flush(); myXmlTextWriter.Close(); }
private void ExportClassDataContract(ClassDataContract classDataContract, XmlSchema schema) { XmlSchemaComplexType type = new XmlSchemaComplexType(); type.Name = classDataContract.StableName.Name; schema.Items.Add(type); XmlElement genericInfoElement = null; if (classDataContract.UnderlyingType.IsGenericType) { genericInfoElement = ExportGenericInfo(classDataContract.UnderlyingType, Globals.GenericTypeLocalName, Globals.SerializationNamespace); } XmlSchemaSequence rootSequence = new XmlSchemaSequence(); for (int i = 0; i < classDataContract.Members.Count; i++) { DataMember dataMember = classDataContract.Members[i]; XmlSchemaElement element = new XmlSchemaElement(); element.Name = dataMember.Name; XmlElement actualTypeElement = null; DataContract memberTypeContract = _dataContractSet.GetMemberTypeDataContract(dataMember); if (CheckIfMemberHasConflict(dataMember)) { element.SchemaTypeName = AnytypeQualifiedName; actualTypeElement = ExportActualType(memberTypeContract.StableName); SchemaHelper.AddSchemaImport(memberTypeContract.StableName.Namespace, schema); } else { SetElementType(element, memberTypeContract, schema); } SchemaHelper.AddElementForm(element, schema); if (dataMember.IsNullable) { element.IsNillable = true; } if (!dataMember.IsRequired) { element.MinOccurs = 0; } element.Annotation = GetSchemaAnnotation(actualTypeElement, ExportSurrogateData(dataMember), ExportEmitDefaultValue(dataMember)); rootSequence.Items.Add(element); } XmlElement isValueTypeElement = null; if (classDataContract.BaseContract != null) { XmlSchemaComplexContentExtension extension = CreateTypeContent(type, classDataContract.BaseContract.StableName, schema); extension.Particle = rootSequence; if (classDataContract.IsReference && !classDataContract.BaseContract.IsReference) { AddReferenceAttributes(extension.Attributes, schema); } } else { type.Particle = rootSequence; if (classDataContract.IsValueType) { isValueTypeElement = GetAnnotationMarkup(IsValueTypeName, XmlConvert.ToString(classDataContract.IsValueType), schema); } if (classDataContract.IsReference) { AddReferenceAttributes(type.Attributes, schema); } } type.Annotation = GetSchemaAnnotation(genericInfoElement, ExportSurrogateData(classDataContract), isValueTypeElement); }
public XmlSchemaElement GetSchema(ServerRuleTypeEnum ruleType) { if (!ruleType.Equals(ServerRuleTypeEnum.Tier1Retention)) { return(null); } XmlSchemaSimpleType timeUnitType = new XmlSchemaSimpleType(); XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction(); restriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet(); enumeration.Value = "minutes"; restriction.Facets.Add(enumeration); enumeration = new XmlSchemaEnumerationFacet(); enumeration.Value = "hours"; restriction.Facets.Add(enumeration); enumeration = new XmlSchemaEnumerationFacet(); enumeration.Value = "days"; restriction.Facets.Add(enumeration); enumeration = new XmlSchemaEnumerationFacet(); enumeration.Value = "weeks"; restriction.Facets.Add(enumeration); enumeration = new XmlSchemaEnumerationFacet(); enumeration.Value = "months"; restriction.Facets.Add(enumeration); enumeration = new XmlSchemaEnumerationFacet(); enumeration.Value = "years"; restriction.Facets.Add(enumeration); timeUnitType.Content = restriction; XmlSchemaSimpleType languageType = new XmlSchemaSimpleType(); XmlSchemaSimpleTypeRestriction languageEnum = new XmlSchemaSimpleTypeRestriction(); languageEnum.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); enumeration = new XmlSchemaEnumerationFacet(); enumeration.Value = "dicom"; languageEnum.Facets.Add(enumeration); languageType.Content = languageEnum; XmlSchemaComplexType type = new XmlSchemaComplexType(); XmlSchemaAttribute attrib = new XmlSchemaAttribute(); attrib.Name = "time"; attrib.Use = XmlSchemaUse.Required; attrib.SchemaTypeName = new XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema"); type.Attributes.Add(attrib); attrib = new XmlSchemaAttribute(); attrib.Name = "unit"; attrib.Use = XmlSchemaUse.Required; attrib.SchemaType = timeUnitType; type.Attributes.Add(attrib); attrib = new XmlSchemaAttribute(); attrib.Name = "refValue"; attrib.Use = XmlSchemaUse.Optional; attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); type.Attributes.Add(attrib); attrib = new XmlSchemaAttribute(); attrib.Name = "expressionLanguage"; attrib.Use = XmlSchemaUse.Optional; attrib.SchemaType = languageType; type.Attributes.Add(attrib); XmlSchemaElement element = new XmlSchemaElement(); element.Name = "tier1-retention"; element.SchemaType = type; return(element); }
/// <summary> /// Run the application with the given arguments. /// </summary> /// <param name="args">The commandline arguments.</param> /// <returns>The number of errors that were found.</returns> private int Run(string[] args) { XmlSchema mainSchema = null; XmlSchemaCollection schemas = new XmlSchemaCollection(); try { this.ParseCommandLine(args); if (this.showLogo) { Assembly thisAssembly = Assembly.GetExecutingAssembly(); Console.WriteLine("Microsoft (R) Windows Installer Xsd Stitch version {0}", thisAssembly.GetName().Version.ToString()); Console.WriteLine("Copyright (C) Microsoft Corporation 2006. All rights reserved."); Console.WriteLine(); } if (this.showHelp) { Console.WriteLine(" usage: xsdStitch.exe mainSchema.xsd stitched.xsd"); Console.WriteLine(); Console.WriteLine(" -ext extSchema.xsd adds an extension schema to the main schema"); Console.WriteLine(" -nologo suppress displaying the logo information"); Console.WriteLine(" -? this help information"); Console.WriteLine(); return(0); } XmlTextReader mainSchemaReader = null; // load the main schema try { mainSchemaReader = new XmlTextReader(this.mainSchemaFile); mainSchema = XmlSchema.Read(mainSchemaReader, null); schemas.Add(mainSchema); } finally { if (null != mainSchemaReader) { mainSchemaReader.Close(); } } StringCollection addedSchemas = new StringCollection(); // load the extension schemas foreach (string extensionSchemaFile in this.extensionSchemaFiles) { XmlTextReader reader = null; try { string schemaFilename = Path.GetFileNameWithoutExtension(extensionSchemaFile); if (addedSchemas.Contains(schemaFilename)) { int duplicateNameCounter = 2; while (addedSchemas.Contains(String.Concat(schemaFilename, duplicateNameCounter))) { duplicateNameCounter++; } schemaFilename = String.Concat(schemaFilename, duplicateNameCounter); } addedSchemas.Add(schemaFilename); reader = new XmlTextReader(extensionSchemaFile); XmlSchema extensionSchema = XmlSchema.Read(reader, null); mainSchema.Namespaces.Add(schemaFilename, extensionSchema.TargetNamespace); schemas.Add(extensionSchema); // add an import for the extension schema XmlSchemaImport import = new XmlSchemaImport(); import.Namespace = extensionSchema.TargetNamespace; import.SchemaLocation = Path.GetFileName(extensionSchemaFile); mainSchema.Includes.Add(import); } finally { if (null != reader) { reader.Close(); } } } foreach (XmlSchema schema in schemas) { if (schema != mainSchema) { foreach (XmlSchemaElement element in schema.Elements.Values) { // retrieve explicitly-specified parent elements if (element.Annotation != null) { foreach (XmlSchemaObject obj in element.Annotation.Items) { XmlSchemaAppInfo appInfo = obj as XmlSchemaAppInfo; if (appInfo != null) { foreach (XmlNode node in appInfo.Markup) { XmlElement markupElement = node as XmlElement; if (markupElement != null && markupElement.LocalName == "parent" && markupElement.NamespaceURI == XmlSchemaExtensionNamespace) { string parentNamespace = markupElement.GetAttribute("namespace"); string parentRef = markupElement.GetAttribute("ref"); if (parentNamespace.Length == 0) { throw new ApplicationException("The parent element is missing the namespace attribute."); } if (parentRef.Length == 0) { throw new ApplicationException("The parent element is missing the ref attribute."); } XmlQualifiedName parentQualifiedName = new XmlQualifiedName(parentRef, parentNamespace); XmlSchemaElement parentElement = (XmlSchemaElement)mainSchema.Elements[parentQualifiedName]; XmlSchemaComplexType complexType = (XmlSchemaComplexType)parentElement.ElementType; if (complexType.Particle != null) { XmlSchemaElement elementRef = new XmlSchemaElement(); elementRef.RefName = element.QualifiedName; this.InsertElement(complexType.Particle, elementRef); } } } } } } } foreach (XmlSchemaAttribute attribute in schema.Attributes.Values) { if (attribute.Annotation != null) { foreach (XmlSchemaObject obj in attribute.Annotation.Items) { XmlSchemaAppInfo appInfo = obj as XmlSchemaAppInfo; if (appInfo != null) { foreach (XmlNode node in appInfo.Markup) { XmlElement markupElement = node as XmlElement; if (markupElement != null && markupElement.LocalName == "parent" && markupElement.NamespaceURI == XmlSchemaExtensionNamespace) { string parentNamespace = markupElement.GetAttribute("namespace"); string parentRef = markupElement.GetAttribute("ref"); if (parentNamespace.Length == 0) { throw new ApplicationException("The parent element is missing the namespace attribute."); } if (parentRef.Length == 0) { throw new ApplicationException("The parent element is missing the ref attribute."); } XmlQualifiedName parentQualifiedName = new XmlQualifiedName(parentRef, parentNamespace); XmlSchemaElement parentElement = (XmlSchemaElement)mainSchema.Elements[parentQualifiedName]; XmlSchemaComplexType complexType = (XmlSchemaComplexType)parentElement.ElementType; if (complexType.Particle != null) { XmlSchemaAttribute attributeRef = new XmlSchemaAttribute(); attributeRef.RefName = attribute.QualifiedName; anyAttributeElements.Add(complexType); complexType.Attributes.Add(attribute); } } } } } } } } } // remove the any items foreach (DictionaryEntry entry in this.anys) { XmlSchemaAny any = (XmlSchemaAny)entry.Key; XmlSchemaParticle particle = (XmlSchemaParticle)entry.Value; if (particle is XmlSchemaChoice) { XmlSchemaChoice choice = (XmlSchemaChoice)particle; choice.Items.Remove(any); } else if (particle is XmlSchemaSequence) { XmlSchemaSequence sequence = (XmlSchemaSequence)particle; sequence.Items.Remove(any); } } // remove anyAttribute items foreach (XmlSchemaComplexType complexType in this.anyAttributeElements) { complexType.AnyAttribute = null; } XmlTextWriter writer = null; try { writer = new XmlTextWriter(this.outputFile, System.Text.Encoding.Default); writer.Indentation = 4; writer.IndentChar = ' '; writer.Formatting = Formatting.Indented; mainSchema.Write(writer); } finally { writer.Close(); } } catch (Exception e) { Console.WriteLine("xsdStitch.exe : fatal error XSDS0001 : {0}\r\n\n\nStack Trace:\r\n{1}", e.Message, e.StackTrace); return(1); } return(0); }
public XmlSchema GetBookSchema() { // <FirstName>: Not required XmlSchemaElement firstNameElement = new XmlSchemaElement(); firstNameElement.Name = "FirstName"; firstNameElement.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); firstNameElement.MinOccurs = 0; // <LastName>: Required XmlSchemaElement lastNameElement = new XmlSchemaElement(); lastNameElement.Name = "LastName"; lastNameElement.MinOccurs = 1; lastNameElement.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <Author>: Required XmlSchemaElement authorElement = new XmlSchemaElement(); authorElement.Name = "Author"; XmlSchemaComplexType authorType = new XmlSchemaComplexType(); XmlSchemaSequence authorSequence = new XmlSchemaSequence(); authorSequence.Items.Add(firstNameElement); authorSequence.Items.Add(lastNameElement); authorType.Particle = authorSequence; authorElement.SchemaType = authorType; // <Name>: Required XmlSchemaElement nameElement = new XmlSchemaElement(); nameElement.Name = "Name"; nameElement.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); nameElement.MinOccurs = 1; // <PlaceOfPublishing>: Not required XmlSchemaElement placeOfPublishingElement = new XmlSchemaElement(); placeOfPublishingElement.Name = "PlaceOfPublishing"; placeOfPublishingElement.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); placeOfPublishingElement.MinOccurs = 0; // <PublishingHouse>: Required XmlSchemaElement publishingHouseElement = new XmlSchemaElement(); publishingHouseElement.Name = "PublishingHouse"; publishingHouseElement.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); publishingHouseElement.MinOccurs = 1; // <YearOfPublishing>: Required XmlSchemaElement yearOfPublishingElement = new XmlSchemaElement(); yearOfPublishingElement.Name = "YearOfPublishing"; yearOfPublishingElement.SchemaTypeName = new XmlQualifiedName("positiveInteger", "http://www.w3.org/2001/XMLSchema"); yearOfPublishingElement.MinOccurs = 1; // <CountOfPages>: Required XmlSchemaElement countOfPagesElement = new XmlSchemaElement(); countOfPagesElement.Name = "CountOfPages"; countOfPagesElement.SchemaTypeName = new XmlQualifiedName("positiveInteger", "http://www.w3.org/2001/XMLSchema"); countOfPagesElement.MinOccurs = 1; // <Notes>: Not required XmlSchemaElement notesElement = new XmlSchemaElement(); notesElement.Name = "Notes"; notesElement.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); notesElement.MinOccurs = 0; // <ISBN>: Required XmlSchemaElement ISBNElement = new XmlSchemaElement(); ISBNElement.Name = "ISBN"; ISBNElement.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); ISBNElement.MinOccurs = 1; XmlSchemaComplexType bookType = new XmlSchemaComplexType(); XmlSchemaSequence bookSequence = new XmlSchemaSequence(); bookSequence.Items.Add(nameElement); bookSequence.Items.Add(authorElement); bookSequence.Items.Add(placeOfPublishingElement); bookSequence.Items.Add(publishingHouseElement); bookSequence.Items.Add(yearOfPublishingElement); bookSequence.Items.Add(countOfPagesElement); bookSequence.Items.Add(notesElement); bookSequence.Items.Add(ISBNElement); bookType.Particle = bookSequence; XmlSchemaElement book = new XmlSchemaElement(); book.Name = "Book"; book.SchemaType = bookType; XmlSchema bookSchema = new XmlSchema(); bookSchema.Items.Add(book); return(bookSchema); }
public static void Main() { XmlSchema schema = new XmlSchema(); // <xs:element name="selected"/> XmlSchemaElement xeSelected = new XmlSchemaElement(); xeSelected.Name = "selected"; schema.Items.Add(xeSelected); // <xs:element name="unselected"/> XmlSchemaElement xeUnselected = new XmlSchemaElement(); xeUnselected.Name = "unselected"; schema.Items.Add(xeUnselected); // <xs:element name="dimpled"/> XmlSchemaElement xeDimpled = new XmlSchemaElement(); xeDimpled.Name = "dimpled"; schema.Items.Add(xeDimpled); // <xs:element name="perforated"/> XmlSchemaElement xePerforated = new XmlSchemaElement(); xePerforated.Name = "perforated"; schema.Items.Add(xePerforated); // <xs:complexType name="chadState"> XmlSchemaComplexType chadState = new XmlSchemaComplexType(); schema.Items.Add(chadState); chadState.Name = "chadState"; // <xs:choice minOccurs="1" maxOccurs="1"> XmlSchemaChoice choice = new XmlSchemaChoice(); chadState.Particle = choice; choice.MinOccurs = 1; choice.MaxOccurs = 1; // <xs:element ref="selected"/> XmlSchemaElement elementSelected = new XmlSchemaElement(); choice.Items.Add(elementSelected); elementSelected.RefName = new XmlQualifiedName("selected"); // <xs:element ref="unselected"/> XmlSchemaElement elementUnselected = new XmlSchemaElement(); choice.Items.Add(elementUnselected); elementUnselected.RefName = new XmlQualifiedName("unselected"); // <xs:element ref="dimpled"/> XmlSchemaElement elementDimpled = new XmlSchemaElement(); choice.Items.Add(elementDimpled); elementDimpled.RefName = new XmlQualifiedName("dimpled"); // <xs:element ref="perforated"/> XmlSchemaElement elementPerforated = new XmlSchemaElement(); choice.Items.Add(elementPerforated); elementPerforated.RefName = new XmlQualifiedName("perforated"); 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); }
private static XmlSchema CreateFakeSoapEncodingSchema(string ns, string name) { var schema = new XmlSchema(); schema.TargetNamespace = ns; var item = new XmlSchemaGroup(); item.Name = "Array"; var sequence = new XmlSchemaSequence(); var any = new XmlSchemaAny(); any.MinOccurs = 0M; any.MaxOccurs = 79228162514264337593543950335M; sequence.Items.Add(any); any.Namespace = "##any"; any.ProcessContents = XmlSchemaContentProcessing.Lax; item.Particle = sequence; schema.Items.Add(item); var type = new XmlSchemaComplexType(); type.Name = name; var ref2 = new XmlSchemaGroupRef(); ref2.RefName = new XmlQualifiedName("Array", ns); type.Particle = ref2; var attribute = new XmlSchemaAttribute(); attribute.RefName = new XmlQualifiedName("arrayType", ns); type.Attributes.Add(attribute); schema.Items.Add(type); attribute = new XmlSchemaAttribute(); attribute.Use = XmlSchemaUse.None; attribute.Name = "arrayType"; schema.Items.Add(attribute); AddSimpleType(schema, "base64", "base64Binary"); AddElementAndType(schema, "anyURI", ns); AddElementAndType(schema, "base64Binary", ns); AddElementAndType(schema, "boolean", ns); AddElementAndType(schema, "byte", ns); AddElementAndType(schema, "date", ns); AddElementAndType(schema, "dateTime", ns); AddElementAndType(schema, "decimal", ns); AddElementAndType(schema, "double", ns); AddElementAndType(schema, "duration", ns); AddElementAndType(schema, "ENTITIES", ns); AddElementAndType(schema, "ENTITY", ns); AddElementAndType(schema, "float", ns); AddElementAndType(schema, "gDay", ns); AddElementAndType(schema, "gMonth", ns); AddElementAndType(schema, "gMonthDay", ns); AddElementAndType(schema, "gYear", ns); AddElementAndType(schema, "gYearMonth", ns); AddElementAndType(schema, "hexBinary", ns); AddElementAndType(schema, "ID", ns); AddElementAndType(schema, "IDREF", ns); AddElementAndType(schema, "IDREFS", ns); AddElementAndType(schema, "int", ns); AddElementAndType(schema, "integer", ns); AddElementAndType(schema, "language", ns); AddElementAndType(schema, "long", ns); AddElementAndType(schema, "Name", ns); AddElementAndType(schema, "NCName", ns); AddElementAndType(schema, "negativeInteger", ns); AddElementAndType(schema, "NMTOKEN", ns); AddElementAndType(schema, "NMTOKENS", ns); AddElementAndType(schema, "nonNegativeInteger", ns); AddElementAndType(schema, "nonPositiveInteger", ns); AddElementAndType(schema, "normalizedString", ns); AddElementAndType(schema, "positiveInteger", ns); AddElementAndType(schema, "QName", ns); AddElementAndType(schema, "short", ns); AddElementAndType(schema, "string", ns); AddElementAndType(schema, "time", ns); AddElementAndType(schema, "token", ns); AddElementAndType(schema, "unsignedByte", ns); AddElementAndType(schema, "unsignedInt", ns); AddElementAndType(schema, "unsignedLong", ns); AddElementAndType(schema, "unsignedShort", ns); return(schema); }
internal static XmlSchemaComplexType GenerateComplexTypeABIE(GeneratorContext context, XmlSchema schema, IAbie abie, string abiePrefix) { // R A4CE, R AF95: a complex type must be defined for each ABIE XmlSchemaComplexType complexTypeBIE = new XmlSchemaComplexType(); // R 9D83: the name of the ABIE must be the DictionaryEntryName with all whitespace and separators // removed. The 'Details' suffix is replaced with 'Type'. complexTypeBIE.Name = abie.Name + "Type"; if (context.Annotate) { complexTypeBIE.Annotation = GetABIEAnnotation(abie); } // create the sequence for the BBIEs within the ABIE XmlSchemaSequence sequenceBBIEs = new XmlSchemaSequence(); foreach (IBbie bbie in abie.Bbies) { // R 89A6: for every BBIE a named element must be locally declared XmlSchemaElement elementBBIE = new XmlSchemaElement(); // R AEFE, R 96D9, R9A40, R A34A are implemented in GetXsdElementNameFromBbie(...) elementBBIE.Name = NDR.GetXsdElementNameFromBbie(bbie); // R 8B85: every BBIE type must be named the property term and qualifiers and the // representation term of the basic business information entity (BBIE) it represents // with the word 'Type' appended. elementBBIE.SchemaTypeName = new XmlQualifiedName(NSPREFIX_BDT + ":" + NDR.GetXsdTypeNameFromBdt(bbie.Bdt)); // R 90F9: cardinality of elements within the ABIE elementBBIE.MinOccursString = AdjustLowerBound(bbie.LowerBound); elementBBIE.MaxOccursString = AdjustUpperBound(bbie.UpperBound); if (context.Annotate) { elementBBIE.Annotation = GetBBIEAnnotation(bbie); } // add the element created to the sequence sequenceBBIEs.Items.Add(elementBBIE); } foreach (IAsbie asbie in abie.Asbies.OrderBy(a => a.Name)) { XmlSchemaElement elementASBIE = new XmlSchemaElement(); // R A08A: name of the ASBIE elementASBIE.Name = NDR.GetXsdElementNameFromAsbie(asbie); elementASBIE.SchemaTypeName = new XmlQualifiedName(abiePrefix + ":" + asbie.AssociatedAbie.Name + "Type"); if (context.Annotate) { elementASBIE.Annotation = GetASBIEAnnotiation(asbie); } if (asbie.AggregationKind == AggregationKind.Shared) { XmlSchemaElement refASBIE = new XmlSchemaElement(); refASBIE.RefName = new XmlQualifiedName(abiePrefix + ":" + elementASBIE.Name); // every shared ASCC may only appear once in the XSD file if (!globalASBIEs.Contains(elementASBIE.Name)) { // R 9241: for ASBIEs with AggregationKind = shared a global element must be declared. schema.Items.Add(elementASBIE); globalASBIEs.Add(elementASBIE.Name); } sequenceBBIEs.Items.Add(refASBIE); } else { //R 9025: ASBIEs with Aggregation Kind = composite a local element for the // associated ABIE must be declared in the associating ABIE complex type. sequenceBBIEs.Items.Add(elementASBIE); } } // add the sequence created to the complex type complexTypeBIE.Particle = sequenceBBIEs; return(complexTypeBIE); }
public static string GetSubRenderingDocument(XmlSchemaComplexType tp, XmlSchemaSet schemas) { return(null); }
public static void Main() { XmlSchema schema = new XmlSchema(); // <xs:complexType name="address"> XmlSchemaComplexType address = new XmlSchemaComplexType(); schema.Items.Add(address); address.Name = "address"; // <xs:sequence> XmlSchemaSequence sequence = new XmlSchemaSequence(); address.Particle = sequence; // <xs:element name="name" type="xs:string"/> XmlSchemaElement elementName = new XmlSchemaElement(); sequence.Items.Add(elementName); elementName.Name = "name"; elementName.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:element name="street" type="xs:string"/> XmlSchemaElement elementStreet = new XmlSchemaElement(); sequence.Items.Add(elementStreet); elementStreet.Name = "street"; elementStreet.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:element name="city" type="xs:string"/> XmlSchemaElement elementCity = new XmlSchemaElement(); sequence.Items.Add(elementCity); elementCity.Name = "city"; elementCity.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:complexType name="USAddress"> XmlSchemaComplexType USAddress = new XmlSchemaComplexType(); schema.Items.Add(USAddress); USAddress.Name = "USAddress"; // <xs:complexContent> XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent(); USAddress.ContentModel = complexContent; // <xs:extension base="address"> XmlSchemaComplexContentExtension extensionAddress = new XmlSchemaComplexContentExtension(); complexContent.Content = extensionAddress; extensionAddress.BaseTypeName = new XmlQualifiedName("address"); // <xs:sequence> XmlSchemaSequence sequence2 = new XmlSchemaSequence(); extensionAddress.Particle = sequence2; // <xs:element name="state" type="xs:string"/> XmlSchemaElement elementUSState = new XmlSchemaElement(); sequence2.Items.Add(elementUSState); elementUSState.Name = "state"; elementUSState.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:element name="zipcode" type="xs:positiveInteger"/> XmlSchemaElement elementZipcode = new XmlSchemaElement(); sequence2.Items.Add(elementZipcode); elementZipcode.Name = "zipcode"; elementZipcode.SchemaTypeName = new XmlQualifiedName("positiveInteger", "http://www.w3.org/2001/XMLSchema"); 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); }
private DomNodeType GetNodeType(XmlSchemaComplexType complexType, XmlSchemaElement element) { // get type name XmlQualifiedName name = complexType.QualifiedName; if (name.IsEmpty) // local type { name = GetLocalTypeName(element); } string typeName = name.ToString(); DomNodeType nodeType; if (!m_nodeTypes.TryGetValue(typeName, out nodeType)) { // build a new complex type and add it to the dictionary nodeType = new DomNodeType(typeName); m_nodeTypes.Add(typeName, nodeType); m_annotations.Add(nodeType, GetAnnotation(complexType)); DomNodeType baseType = null; XmlAttributeType valueType = null; XmlSchemaComplexType complexBaseType = GetBaseType(complexType); if (complexBaseType != null) { baseType = GetNodeType(complexBaseType, null); } XmlSchemaSimpleType simpleBase = complexType.BaseXmlSchemaType as XmlSchemaSimpleType; if (simpleBase != null) { valueType = GetAttributeType(simpleBase); } else if (complexType.IsMixed) { valueType = s_mixedTextFieldSimpleType; } WalkParticle(complexType.ContentTypeParticle, nodeType); if (valueType != null) { XmlAttributeInfo attributeInfo = new XmlAttributeInfo(string.Empty, valueType); nodeType.Define(attributeInfo); } // get XML attributes System.Collections.ICollection attributeUses = complexType.AttributeUses.Values; foreach (XmlSchemaAttribute attribute in attributeUses) { XmlAttributeType attributeType = GetAttributeType(attribute.AttributeSchemaType); string fieldName = GetFieldName(attribute.QualifiedName); XmlAttributeInfo attributeInfo = new XmlAttributeInfo(fieldName, attributeType); if (attribute.DefaultValue != null) { attributeInfo.DefaultValue = attributeType.Convert(attribute.DefaultValue); } m_annotations.Add(attributeInfo, GetAnnotation(attribute)); nodeType.Define(attributeInfo); } if (baseType != null) { nodeType.BaseType = baseType; } nodeType.IsAbstract = complexType.IsAbstract; } return(nodeType); }
internal XmlSerializableMapping(XmlRootAttribute root, string elementName, string ns, TypeData typeData, string xmlType, string xmlTypeNamespace) : base(elementName, ns, typeData, xmlType, xmlTypeNamespace) { #if NET_2_0 XmlSchemaProviderAttribute schemaProvider = (XmlSchemaProviderAttribute)Attribute.GetCustomAttribute(typeData.Type, typeof(XmlSchemaProviderAttribute)); if (schemaProvider != null) { string method = schemaProvider.MethodName; MethodInfo mi = typeData.Type.GetMethod(method, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy); if (mi == null) { throw new InvalidOperationException(String.Format("Type '{0}' must implement public static method '{1}'", typeData.Type, method)); } if (!typeof(XmlQualifiedName).IsAssignableFrom(mi.ReturnType) && // LAMESPEC: it is undocumented. (We don't have to tell users about it in the error message.) // Also do not add such a silly compatibility test to assert that it does not raise an error. !typeof(XmlSchemaComplexType).IsAssignableFrom(mi.ReturnType)) { throw new InvalidOperationException(String.Format("Method '{0}' indicated by XmlSchemaProviderAttribute must have its return type as XmlQualifiedName", method)); } XmlSchemaSet xs = new XmlSchemaSet(); object retVal = mi.Invoke(null, new object [] { xs }); _schemaTypeName = XmlQualifiedName.Empty; if (retVal == null) { return; } if (retVal is XmlSchemaComplexType) { _schemaType = (XmlSchemaComplexType)retVal; if (!_schemaType.QualifiedName.IsEmpty) { _schemaTypeName = _schemaType.QualifiedName; } else { _schemaTypeName = new XmlQualifiedName(xmlType, xmlTypeNamespace); } } else if (retVal is XmlQualifiedName) { _schemaTypeName = (XmlQualifiedName)retVal; } else { throw new InvalidOperationException( String.Format("Method {0}.{1}() specified by XmlSchemaProviderAttribute has invalid signature: return type must be compatible with System.Xml.XmlQualifiedName.", typeData.Type.Name, method)); } // defaultNamespace at XmlReflectionImporter takes precedence for Namespace, but not for XsdTypeNamespace. UpdateRoot(new XmlQualifiedName(root != null ? root.ElementName : _schemaTypeName.Name, root != null ? root.Namespace : Namespace ?? _schemaTypeName.Namespace)); XmlTypeNamespace = _schemaTypeName.Namespace; XmlType = _schemaTypeName.Name; if (!_schemaTypeName.IsEmpty && xs.Count > 0) { XmlSchema [] schemas = new XmlSchema [xs.Count]; xs.CopyTo(schemas, 0); _schema = schemas [0]; } return; } #endif IXmlSerializable serializable = (IXmlSerializable)Activator.CreateInstance(typeData.Type, true); #if NET_2_0 try { _schema = serializable.GetSchema(); } catch (Exception) { // LAMESPEC: .NET has a bad exception catch and swallows it silently. } #else _schema = serializable.GetSchema(); #endif if (_schema != null) { if (_schema.Id == null || _schema.Id.Length == 0) { throw new InvalidOperationException("Schema Id is missing. The schema returned from " + typeData.Type.FullName + ".GetSchema() must have an Id."); } } }
private void WalkParticle(XmlSchemaParticle particle, DomNodeType nodeType) { XmlSchemaElement element = particle as XmlSchemaElement; if (element != null) { XmlSchemaSimpleType simpleType = element.ElementSchemaType as XmlSchemaSimpleType; if (simpleType != null && element.MaxOccurs == 1) { XmlAttributeType attributeType = GetAttributeType(simpleType); string fieldName = GetFieldName(element.QualifiedName); XmlAttributeInfo attributeInfo = new XmlAttributeInfo(fieldName, attributeType); nodeType.Define(attributeInfo); m_annotations.Add(attributeInfo, GetAnnotation(element)); attributeInfo.IsElement = true; if (element.DefaultValue != null) { if (element.FixedValue != null) { throw new InvalidOperationException(string.Format("Schema element {0} cannot have both a default value and a fixed value", element.QualifiedName)); } attributeInfo.DefaultValue = attributeType.Convert(element.DefaultValue); } else if (element.FixedValue != null) { attributeInfo.DefaultValue = attributeType.Convert(element.FixedValue); } } else { DomNodeType childNodeType = null; if (simpleType != null) { bool firstTime; childNodeType = WrapSimpleType(simpleType, out firstTime); // The collada.xsd's ListOfUInts element breaks the generated Schema.cs file otherwise. if (firstTime) { // Add the value attribute XmlAttributeType valueAttributeType = GetAttributeType(simpleType); var valueAttributeInfo = new XmlAttributeInfo(string.Empty, valueAttributeType); childNodeType.Define(valueAttributeInfo); } } else { XmlSchemaComplexType complexType = element.ElementSchemaType as XmlSchemaComplexType; if (complexType != null) { childNodeType = GetNodeType(complexType, element); } } if (childNodeType != null) { int minOccurs = (int)Math.Min(element.MinOccurs, Int32.MaxValue); int maxOccurs = (int)Math.Min(element.MaxOccurs, Int32.MaxValue); if (particle.Parent is XmlSchemaChoice) { var parent = (XmlSchemaChoice)particle.Parent; if (parent.MinOccurs != 1) { minOccurs = (int)Math.Min(Math.Max(element.MinOccurs, parent.MinOccurs), Int32.MaxValue); } if (parent.MaxOccurs != 1) { maxOccurs = (int)Math.Min(Math.Max(element.MaxOccurs, parent.MaxOccurs), Int32.MaxValue); } } else if (particle.Parent is XmlSchemaSequence) { var parent = (XmlSchemaSequence)particle.Parent; if (parent.MinOccurs != 1) { minOccurs = (int)Math.Min(Math.Max(element.MinOccurs, parent.MinOccurs), Int32.MaxValue); } if (parent.MaxOccurs != 1) { maxOccurs = (int)Math.Min(Math.Max(element.MaxOccurs, parent.MaxOccurs), Int32.MaxValue); } } ChildInfo childInfo = new ChildInfo(GetFieldName(element.QualifiedName), childNodeType, maxOccurs > 1); if ((minOccurs > 0 || maxOccurs < Int32.MaxValue) && minOccurs <= maxOccurs) { childInfo.AddRule(new ChildCountRule(minOccurs, maxOccurs)); } // Check for substitution groups if (!element.RefName.IsEmpty) { m_refElements.Add(childInfo, element.RefName); } nodeType.Define(childInfo); m_annotations.Add(childInfo, GetAnnotation(element)); } } } else { XmlSchemaGroupBase grp = particle as XmlSchemaSequence; if (grp == null) { grp = particle as XmlSchemaChoice; } if (grp == null) { grp = particle as XmlSchemaAll; } if (grp != null) { foreach (XmlSchemaParticle subParticle in grp.Items) { WalkParticle(subParticle, nodeType); } } } }
private XmlSchemaGroupBase AddSequence(XmlSchemaGroupBase schema, string name, bool required, XmlSchemaComplexType type = null) { var element = new XmlSchemaElement(); if (!required) { element.MinOccurs = 0; element.MaxOccurs = 1; } XmlSchemaComplexType currentType = type == null ? new XmlSchemaComplexType() : type; var all = new XmlSchemaSequence(); element.Name = name; if (type == null) { element.SchemaType = currentType; } else { element.SchemaTypeName = new XmlQualifiedName(currentType.Name); } currentType.Particle = all; schema.Items.Add(element); return(all); }
/// <summary> /// Creates a new instance of the <see cref="NAntSchemaGenerator" /> /// class. /// </summary> /// <param name="tasks">Tasks for which a schema should be generated.</param> /// <param name="dataTypes">Data Types for which a schema should be generated.</param> /// <param name="targetNS">The namespace to use. /// <example> http://tempuri.org/nant.xsd </example> /// </param> public NAntSchemaGenerator(Type[] tasks, Type[] dataTypes, string targetNS) { //setup namespace stuff if (targetNS != null) { _nantSchema.TargetNamespace = targetNS; _nantSchema.Namespaces.Add("nant", _nantSchema.TargetNamespace); } // add XSD namespace so that all xsd elements are prefix'd _nantSchema.Namespaces.Add("xs", XmlSchema.Namespace); _nantSchema.ElementFormDefault = XmlSchemaForm.Qualified; // initialize stuff _nantComplexTypes = new HybridDictionary(tasks.Length + dataTypes.Length); XmlSchemaAnnotation schemaAnnotation = new XmlSchemaAnnotation(); XmlSchemaDocumentation schemaDocumentation = new XmlSchemaDocumentation(); string doc = String.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("String_SchemaGenerated"), DateTime.Now); schemaDocumentation.Markup = TextToNodeArray(doc); schemaAnnotation.Items.Add(schemaDocumentation); _nantSchema.Items.Add(schemaAnnotation); // create temp list of taskcontainer Complex Types ArrayList taskContainerComplexTypes = new ArrayList(4); XmlSchemaComplexType containerCT = FindOrCreateComplexType(typeof(TaskContainer)); if (containerCT.Particle == null) { // just create empty sequence to which elements will // be added later containerCT.Particle = CreateXsdSequence(0, Decimal.MaxValue); } taskContainerComplexTypes.Add(containerCT); // create temp list of task Complex Types ArrayList dataTypeComplexTypes = new ArrayList(dataTypes.Length); foreach (Type t in dataTypes) { dataTypeComplexTypes.Add(FindOrCreateComplexType(t)); } foreach (Type t in tasks) { XmlSchemaComplexType taskCT = FindOrCreateComplexType(t); // allow any tasks... if (t.IsSubclassOf(typeof(TaskContainer))) { taskContainerComplexTypes.Add(taskCT); } } Compile(); // update the taskcontainerCTs to allow any other task and the // list of tasks generated foreach (XmlSchemaComplexType ct in taskContainerComplexTypes) { XmlSchemaSequence seq = ct.Particle as XmlSchemaSequence; if (seq != null) { seq.Items.Add(CreateTaskListComplexType(tasks).Particle); } else { logger.Error("Unable to fixup complextype with children. Particle is not XmlSchemaSequence"); } } Compile(); // create target ComplexType _targetCT = CreateTaskListComplexType(tasks, dataTypes, false); _targetCT.Name = "Target"; // This is a response to Bug#: 3058913. If not considered neccessary, remove line below. _targetCT.IsMixed = true; // name attribute _targetCT.Attributes.Add(CreateXsdAttribute("name", true)); // depends attribute _targetCT.Attributes.Add(CreateXsdAttribute("depends", false)); // description attribute _targetCT.Attributes.Add(CreateXsdAttribute("description", false)); // if attribute _targetCT.Attributes.Add(CreateXsdAttribute("if", false)); // unless attribute _targetCT.Attributes.Add(CreateXsdAttribute("unless", false)); _nantSchema.Items.Add(_targetCT); Compile(); // Generate project Element and ComplexType XmlSchemaElement projectElement = new XmlSchemaElement(); projectElement.Name = "project"; XmlSchemaComplexType projectCT = CreateTaskListComplexType(tasks, dataTypes, true); projectElement.SchemaType = projectCT; //name attribute projectCT.Attributes.Add(CreateXsdAttribute("name", true)); //default attribute projectCT.Attributes.Add(CreateXsdAttribute("default", false)); //basedir attribute projectCT.Attributes.Add(CreateXsdAttribute("basedir", false)); _nantSchema.Items.Add(projectElement); Compile(); }
private void UpdataSchema(Dictionary <int, Dictionary <int, string> > contentMap, XmlSchema schema, XmlSchemaGroupBase container, Content content, Field definitionfield, bool isExstension = false, bool isBackward = false) { var exstensionFields = content.Fields.OfType <ExtensionField>().ToArray(); if (exstensionFields.Length > 1) { throw new Exception("Content " + content.ContentId + " has more than one ExtensionField"); } var exstensionField = exstensionFields.FirstOrDefault(); if (exstensionField != null && exstensionField.ContentMapping.Count() > 1) { if (exstensionField.ContentMapping.Values.Any(c => c.Fields.Any() || c.LoadAllPlainFields)) { throw new Exception("Multiple exstensions are not supported for Content " + content.ContentId + " " + string.Join(",", exstensionField.ContentMapping.Select(x => x.Key))); } } var articleFields = _fieldService.List(content.ContentId).ToArray(); if (articleFields.Any()) { var articleContent = articleFields.First().Content; var article = container; if (!isExstension) { if (definitionfield == null) { var articles = AddElement(container, articleContent.NetPluralName, true); if (exstensionField != null && exstensionField.ContentMapping.Any()) { int exstensionContentId = exstensionField.ContentMapping.First().Value.ContentId; var exstensionContent = _contentService.Read(exstensionContentId); article = AddType(schema, articles, articleContent.NetName, exstensionContent.NetName, exstensionContent.Name); } else { article = AddElement(articles, articleContent.NetName, true); } } else { var field = _fieldService.Read(definitionfield.FieldId); bool required = field.Required && !isBackward; string fieldName = definitionfield.FieldName ?? field.Name; int key = content.GetHashCode(); Dictionary <int, string> keyMap = null; XmlSchemaComplexType type = null; if (contentMap.TryGetValue(content.ContentId, out keyMap)) { string typeName = null; if (keyMap.TryGetValue(key, out typeName)) { if (typeName == null) { int typeNameCount = keyMap.Values.Count(v => v != null); typeName = articleContent.NetName; if (typeNameCount > 0) { typeName += "_" + (typeNameCount + 1); } type = RegisterType(schema, typeName, articleContent.Name); keyMap[key] = typeName; } else { if (field.RelationType == Quantumart.QP8.BLL.RelationType.OneToMany && !isBackward) { AddElement(container, fieldName, new XmlQualifiedName(typeName), required); } else { var articles = AddSequence(container, fieldName, required); AddElement(articles, articleContent.NetName, new XmlQualifiedName(typeName), required, true); } return; } } } if (field.RelationType == Quantumart.QP8.BLL.RelationType.OneToMany && !isBackward) { article = AddElement(container, fieldName, required, type: type); } else { var articles = AddSequence(container, fieldName, required); article = AddElement(articles, articleContent.NetName, required, true, type: type); } } AddElement(article, "Id", IntegerType); } var plainArticleFields = articleFields.Where(f => f.RelationType == Quantumart.QP8.BLL.RelationType.None); var plainFields = from articleField in plainArticleFields join defField in content.Fields.OfType <PlainField>() on articleField.Id equals defField.FieldId into fs from defField in fs.DefaultIfEmpty() select new { Name = defField == null ? articleField.Name : defField.FieldName, Type = GetElementType(articleField), Required = articleField.Required, HasDefinition = defField != null, ArticleField = articleField }; foreach (var field in plainFields) { if (content.LoadAllPlainFields || field.HasDefinition) { if (field.ArticleField.StringEnumItems.Any()) { AddEnumElement(article, field.Name, field.ArticleField, field.Required); } else { AddElement(article, field.Name, field.Type, field.Required); } } } foreach (var field in content.Fields.OfType <EntityField>()) { bool backward = field is BackwardRelationField; UpdataSchema(contentMap, schema, article, field.Content, field, false, backward); } if (exstensionField != null) { var exstensionContent = exstensionField.ContentMapping.Values.FirstOrDefault(); if (exstensionContent != null) { UpdataSchema(contentMap, schema, article, exstensionContent, exstensionField, true, false); } } } }
protected XmlSchemaComplexType FindOrCreateComplexType(Type t) { XmlSchemaComplexType ct; string typeId = GenerateIDFromType(t); ct = FindComplexTypeByID(typeId); if (ct != null) { return(ct); } ct = new XmlSchemaComplexType(); ct.Name = typeId; // Force mixed attribute for tasks names in the mixedTaskNames array. Fixes Bug#: 3058913 if (Array.IndexOf(mixedTaskNames, ct.Name) != -1) { ct.IsMixed = true; } // add complex type to collection immediately to avoid stack // overflows, when we allow a type to be nested _nantComplexTypes.Add(typeId, ct); #if NOT_IMPLEMENTED // // TODO - add task/type documentation in the future // ct.Annotation = new XmlSchemaAnnotation(); XmlSchemaDocumentation doc = new XmlSchemaDocumentation(); ct.Annotation.Items.Add(doc); doc.Markup = ...; #endif XmlSchemaSequence group1 = null; XmlSchemaObjectCollection attributesCollection = ct.Attributes; foreach (MemberInfo memInfo in t.GetMembers(BindingFlags.Instance | BindingFlags.Public)) { if (memInfo.DeclaringType.Equals(typeof(object))) { continue; } //Check for any return type that is derived from Element // add Attributes TaskAttributeAttribute taskAttrAttr = (TaskAttributeAttribute) Attribute.GetCustomAttribute(memInfo, typeof(TaskAttributeAttribute), false); BuildElementAttribute buildElemAttr = (BuildElementAttribute) Attribute.GetCustomAttribute(memInfo, typeof(BuildElementAttribute), false); if (taskAttrAttr != null) { XmlSchemaAttribute newAttr = CreateXsdAttribute(taskAttrAttr.Name, taskAttrAttr.Required); attributesCollection.Add(newAttr); } else if (buildElemAttr != null) { // Create individial choice for any individual child Element Decimal min = 0; if (buildElemAttr.Required) { min = 1; } XmlSchemaElement childElement = new XmlSchemaElement(); childElement.MinOccurs = min; childElement.MaxOccurs = 1; childElement.Name = buildElemAttr.Name; //XmlSchemaGroupBase elementGroup = CreateXsdSequence(min, Decimal.MaxValue); Type childType; // We will only process child elements if they are defined for Properties or Fields, this should be enforced by the AttributeUsage on the Attribute class if (memInfo is PropertyInfo) { childType = ((PropertyInfo)memInfo).PropertyType; } else if (memInfo is FieldInfo) { childType = ((FieldInfo)memInfo).FieldType; } else if (memInfo is MethodInfo) { MethodInfo method = (MethodInfo)memInfo; if (method.GetParameters().Length == 1) { childType = method.GetParameters()[0].ParameterType; } else { throw new ApplicationException("Method should have one parameter."); } } else { throw new ApplicationException("Member Type != Field/Property/Method"); } BuildElementArrayAttribute buildElementArrayAttribute = (BuildElementArrayAttribute) Attribute.GetCustomAttribute(memInfo, typeof(BuildElementArrayAttribute), false); // determine type of child elements if (buildElementArrayAttribute != null) { if (buildElementArrayAttribute.ElementType == null) { if (childType.IsArray) { childType = childType.GetElementType(); } else { Type elementType = null; // locate Add method with 1 parameter, type of that parameter is parameter type foreach (MethodInfo method in childType.GetMethods(BindingFlags.Public | BindingFlags.Instance)) { if (method.Name == "Add" && method.GetParameters().Length == 1) { ParameterInfo parameter = method.GetParameters()[0]; elementType = parameter.ParameterType; break; } } childType = elementType; } } else { childType = buildElementArrayAttribute.ElementType; } if (childType == null || !typeof(Element).IsAssignableFrom(childType)) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1140"), memInfo.DeclaringType.FullName, memInfo.Name)); } } BuildElementCollectionAttribute buildElementCollectionAttribute = (BuildElementCollectionAttribute)Attribute.GetCustomAttribute(memInfo, typeof(BuildElementCollectionAttribute), false); if (buildElementCollectionAttribute != null) { XmlSchemaComplexType collectionType = new XmlSchemaComplexType(); XmlSchemaSequence sequence = new XmlSchemaSequence(); collectionType.Particle = sequence; sequence.MinOccurs = 0; sequence.MaxOccursString = "unbounded"; XmlSchemaElement itemType = new XmlSchemaElement(); itemType.Name = buildElementCollectionAttribute.ChildElementName; itemType.SchemaTypeName = FindOrCreateComplexType(childType).QualifiedName; sequence.Items.Add(itemType); childElement.SchemaType = collectionType; } else { childElement.SchemaTypeName = FindOrCreateComplexType(childType).QualifiedName; } // lazy init of sequence if (group1 == null) { group1 = CreateXsdSequence(0, Decimal.MaxValue); ct.Particle = group1; } group1.Items.Add(childElement); } } // allow attributes from other namespace ct.AnyAttribute = new XmlSchemaAnyAttribute(); ct.AnyAttribute.Namespace = "##other"; ct.AnyAttribute.ProcessContents = XmlSchemaContentProcessing.Skip; Schema.Items.Add(ct); Compile(); return(ct); }