本文介绍了我们可以在XSD.EXE生成工具类控制类型名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

xsd.exe工具生成的类特定XSD文件。它遵循命名类型的图案。例如,

xsd.exe tool generates classes for given xsd file. It follows a pattern for naming the type.For example,

<Students>
  <Student Name="A" RollNo="1" Address="Some Address">
    <Department Id="20" Name="CSE"/>
  </Student>
</Students>

xsd.exe /c Students.xsd

生成

Students.cs文件。如果我们看到的元素类型

Students.cs file is generated. If we see the type for elements

Element     Type Name
Students    Students
Student     StudentsStudent
Department  StudentsStudentDepartment

它会产生由prefixing父元素的名称,如果该元素是子类型。我们可以控制这个名字呢?我需要的类型名称相同的元素名称。学生=>学生,系=>部

It generates type by prefixing the parent element name if the element is child.Can we control this name? I need the type name as same as element name.Student => Student, Department => Department

在此先感谢

推荐答案

在一般情况下,一个人不能使用XSD.EXE时自定义生成的类的名称 - 不像现有的机制在其他地方,对于如通过自定义JAXB绑定文件JAXB用户。

In general, one cannot customize the names of the generated classes when using xsd.exe - unlike mechanisms available elsewhere, for e.g. a JAXB user through custom JAXB binding file.

不过,对于XSD.EXE生成的类名取决于创作风格。你所描述的,是当创作风格是一致的俄罗斯套娃,即生成如下:

However, for xsd.exe the generated class names depend on the authoring style. What you described, is generated when the authoring style is conformant to the "Russian Doll" i.e. as below:

<?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>

如果你改变它的风格,以不同的东西(这被称为百叶窗):

If you change its style to something different (this is called a Venetian Blind):

<?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>

您会得到这些类生成的:

You'll be getting these classes generated:

这篇关于我们可以在XSD.EXE生成工具类控制类型名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:25