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

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

本文介绍了xsd到xsd文件中带下划线的java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下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>

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

As you can see in this I Have '_' in the Customer_Info complex type. Now when I generate Java files using JAXB's xjc command I get file name as CustomerInfo.java.Also I want to have the type of flatNo as String in my generated Java files

....而我希望获得文件名为Customer_Info.java 。谁可以帮我这个事?在此先感谢...

....whereas I desire to get the filename as Customer_Info.java. Can anyone help me on this? Thanks in advance...

推荐答案

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

You can use an external binding file to keep the _.

<?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 引用绑定文件的选项。

When using xjc you can use the -b option to reference the binding file.

xjc -b binding.xml schema.xsd

这篇关于xsd到xsd文件中带下划线的java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 05:55