C# Help: Adding a complexType to the main XmlSchema
I need to create program that creates a XML schema like below using System.Xml.XmlSchema namespace
I'm using the XmlSchemaComplexType
to MyString and MyInteger but I can't seem to find a way to set the extension to base string and int respectively.
Any guidance is much appreciated ... thanks
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="MyString">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="modified" type="xs:boolean" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="MyInteger">
<xs:simpleContent>
<xs:extension base="xs:int">
<xs:attribute name="modified" type="xs:boolean" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name="data">
<xs:complexType>
<xs:sequence>
<xs:element name="row">
开发者_如何学C <xs:complexType>
<xs:sequence>
<xs:element name="order_id" type="MyInteger" />
<xs:element name="order_status" type="MyString" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I believe something like this should do the trick:
// <xs:simpleContent>
XmlSchemaSimpleContent simpleContent = new XmlSchemaSimpleContent();
// <xs:extension base="xs:string">
XmlSchemaSimpleContentExtension simpleContent_extension =
new XmlSchemaSimpleContentExtension();
simpleContent_extension.BaseTypeName =
new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
See the example at the bottom of this page for context.
精彩评论