xsd.exe工具为给定的xsd文件生成类。它遵循命名类型的模式。 例如,
<Students>
<Student Name="A" RollNo="1" Address="Some Address">
<Department Id="20" Name="CSE"/>
</Student>
</Students>
xsd.exe /c Students.xsd
生成Students.cs文件。如果我们看到元素的类型
Element Type Name
Students Students
Student StudentsStudent
Department StudentsStudentDepartment
如果元素是child,则通过为父元素名称添加前缀来生成类型。 我们可以控制这个名字吗?我需要类型名称与元素名称相同。 学生=&gt;学生,部门=&gt;系
先谢谢
答案 0 :(得分:22)
通常,在使用xsd.exe时无法自定义生成的类的名称 - 与其他地方可用的机制不同,例如JAXB用户通过自定义JAXB绑定文件。
但是,对于xsd.exe,生成的类名取决于创作样式。您所描述的内容是在创作风格符合“俄罗斯娃娃”时生成的,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Students">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Student">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Department">
<xsd:complexType>
<xsd:attribute name="Id" type="xsd:unsignedByte" use="required" />
<xsd:attribute name="Name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="Name" type="xsd:string" use="required" />
<xsd:attribute name="RollNo" type="xsd:unsignedByte" use="required" />
<xsd:attribute name="Address" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
如果你将它的风格改为不同的东西(这被称为威尼斯盲人):
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Students" type="Students"/>
<xsd:complexType name="Students">
<xsd:sequence>
<xsd:element name="Student" type="Student"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Student">
<xsd:sequence>
<xsd:element name="Department" type="Department"/>
</xsd:sequence>
<xsd:attribute name="Name" type="xsd:string" use="required"/>
<xsd:attribute name="RollNo" type="xsd:unsignedByte" use="required"/>
<xsd:attribute name="Address" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="Department">
<xsd:attribute name="Id" type="xsd:unsignedByte" use="required"/>
<xsd:attribute name="Name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:schema>
您将获得这些类: