Make xsd.exe utility generate schema with strong types

  Uncategorised

I have this sample XML file:

<?xml version="1.0"?>
<DocumentElement>
  <item>
    <id>1</id>
    <name>BBB</name>
  </item>
  <item>
    <id>2</id>
    <name>BBB</name>
  </item>
</DocumentElement>

I want to generate XSD schema using xsd.exe utility and run this command:

xsd.exe myXmlFile.xml

This is what I got on output:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="DocumentElement" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="DocumentElement" msdata:IsDataSet="true" msdata:Locale="en-US">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="item">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="id" type="xs:string" minOccurs="0" />
              <xs:element name="name" type="xs:string" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

Notice both fields are string but I expected them to be an integer and a string.
If I generate schema in VS then I get a better result:

      <xs:element name="id" type="xs:unsignedByte" />
      <xs:element name="name" type="xs:string" />

How can I make xsd.exe work like in VS?

Source: Visual Studio Questions

LEAVE A COMMENT