tags:

views:

16

answers:

1

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"&gt;
    <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">
                    <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>
+1  A: 

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.

DanM
Thanks DanM, only more extra step XmlSchemaComplexType complexType = new XmlSchemaComplexType (); complexType.ContentModel = simpleContent;
G33kKahuna