出于某种原因,MS .Net (v3.5) 工具 - xsd.exe 在未在任何元素内使用时不会生成类型。
例如
XSD 文件(我加入了复杂元素以避免此警告 - “警告:无法生成类,因为没有找到具有复杂类型的顶级元素。”):
<?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>
当我通过 xsd.exe 使用
xsd /c xsdfile.xsd
我在生成的 cs 文件中没有看到 EnumTest。
笔记; 尽管我在这里没有使用枚举,但在我的实际项目中,我有这样的情况,我们将枚举的字符串值作为输出发送。
如何强制 xsd 工具包含这些?还是我应该切换到其他工具?
我在 Visual Studio 2008 中工作。