.Net xsd.exe tool doesn't generate all types

Posted by Mrchief on Stack Overflow See other posts from Stack Overflow or by Mrchief
Published on 2010-01-26T19:58:43Z Indexed on 2010/06/08 9:52 UTC
Read the original article Hit count: 326

Filed under:
|
|

For some reason, MS .Net (v3.5) tool - xsd.exe doesn't generate types when they are not used inside any element.

e.g.

XSD File (I threw in the complex element to avoid this warning - "Warning: cannot generate classes because no top-level elements with complex type were found."):

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/XMLSchema.xsd"
    xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
  <xs:simpleType name="EnumTest">
    <xs:restriction base="xs:string">
      <xs:enumeration value="item1" />
      <xs:enumeration value="item2" />
      <xs:enumeration value="item3" />
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="myComplexType">
    <xs:attribute name="Name" use="required" type="xs:string"/>
  </xs:complexType>
  <xs:element name="myElem" type="myComplexType"></xs:element>
</xs:schema>

When i run this thru xsd.exe using

xsd /c xsdfile.xsd

I don't see EnumTest in the generated cs file.

Note; Even though I don't use the enum here, but in my actual project, I have cases like this where we send enum's string value as output.

How can I force the xsd tool to include these? Or should I switch to some other tool?

I work in Visual Studio 2008.

© Stack Overflow or respective owner

Related posts about type

Related posts about xsd.exe