Search code examples
c#xmlxsdxdr

Difference B/W MS XML Schema vs XSD Schema


I have been dwindling around a while but could not find any tutorials or resources about an XML Schema provided by Microsoft in this link. It looks like:

<Schema xmlns="urn:schemas-microsoft-com:xml-data" 
  xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <AttributeType name='studentID' dt:type='string' required='yes'/>
  <ElementType name='name' content='textOnly'/>
  <ElementType name='GPA' content='textOnly' dt:type='float'/>
  <ElementType name='student' content='mixed'>
    <attribute type='studentID'/>
    <element type='name'/>
    <element type='GPA'/>
  </ElementType>
  <ElementType name='class' content='eltOnly'>
    <element type='student'/>
  </ElementType>
</Schema>  

I know this is not a W3C recommended XSD format... I am facing difficulty to know how to read and make a standard format XSD out of it. I also wish to generate C# classes from it.

Any help would be appreciated. It has really confused my understanding of XML schemas.


Solution

  • That is an XDR schema. If you want to transform that file to a W3C XML schema on Windows with the .NET framework or Visual Studio SDK installed you can use the xsd.exe command line tool i.e. xsd.exe schema.xdr will create a corresponding schema.xsd file. Then you can apply xsd.exe on the schema.xsd to create class files in C# or VB.NET to be used with System.Xml.Serialization.XmlSerializer.

    When I run VS 2012's xsd.exe on your sample it creates the following W3C XSD schema:

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
      <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
        <xs:complexType>
          <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="class">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="student" minOccurs="0" maxOccurs="unbounded">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="name" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
                        <xs:element name="GPA" type="xs:double" minOccurs="0" msdata:Ordinal="2" />
                      </xs:sequence>
                      <xs:attribute name="studentID" type="xs:string" />
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:choice>
        </xs:complexType>
      </xs:element>
    </xs:schema>