xsd到xsd文件中带下划线的java

时间:2013-08-19 06:58:11

标签: xml jaxb xsd xjc

考虑以下xsd文件:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Customer_Info" type="Customer"/>
<xsd:complexType name="Customer_Info">
  <xsd:all>
    <xsd:element name="Profile" type="Profile" minOccurs="1" maxOccurs="1"/>
    <xsd:element name="Address" type="integer" minOccurs="1" maxOccurs="1"/>
  </xsd:all>
</xsd:complexType>
<xsd:complexType name="Profile">
  <xsd:all>
    <xsd:element name="Name" minOccurs="1">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
          <xsd:maxLength value="100"/>
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:element>
    <xsd:element name="Email" minOccurs="0">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
          <xsd:maxLength value="50"/>
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:element>
    <xsd:element name="Phone" maxOccurs="1">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
          <xsd:maxLength value="12"/>
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:element>
  </xsd:all>
</xsd:complexType>
<xsd:complexType name="Address">
  <xsd:all>
    <xsd:element name="FlatNo" minOccurs="1">
      <xsd:simpleType>
        <xsd:restriction base="xsd:integer">
          <xsd:maxLength value="100"/>
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:element>
    <xsd:element name="Street" minOccurs="1">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
          <xsd:maxLength value="100"/>
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:element>
    <xsd:element name="Landmark" minOccurs="0">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
          <xsd:maxLength value="100"/>
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:element>
  </xsd:all>
</xsd:complexType>
</xsd:schema>

正如你在我看到的那样,我有&#39; _&#39;在Customer_Info复杂类型中。现在,当我使用JAXB的xjc命令生成Java文件时,我得到文件名为CustomerInfo.java。 另外,我想在生成的Java文件中使用flatNo类型作为String

....而我希望获得文件名为Customer_Info.java。谁可以帮我这个事?提前谢谢......

1 个答案:

答案 0 :(得分:3)

您可以使用外部绑定文件来保留_

<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings 
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
  version="2.1">
  <jxb:globalBindings underscoreBinding="asCharInWord"/>
</jxb:bindings>

使用xjc时,您可以使用-b选项来引用绑定文件。

xjc -b binding.xml schema.xsd