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.
I'll have to conclude this is a stupid shortcoming of the tool. Maybe give a switch to turn on this behavior. By not having this behavior, I'm forced to create types outside of xsd and that creates fragmented code.
This is my personal opinion and I'm pretty sure there are others who would share the same.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With