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

Mrchief picture Mrchief · Jan 26, 2010 · Viewed 14.1k times · Source

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.

Answer

Sruly picture Sruly · Nov 30, 2010

I know this is very old, but it came up in google when I was searching and I found an answer.

An Xsd has to have at lease one xs:element to be valid and for xsd.exe to work right.

look at this for more info http://keithelder.net/2008/11/02/creating-a-rest-wcf-service-from-an-existing-xsd-schema/