Reputation: 43
Consider the below xsd file:
<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>
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
....whereas I desire to get the filename as Customer_Info.java. Can anyone help me on this? Thanks in advance...
Upvotes: 2
Views: 1977
Reputation: 149017
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>
When using xjc
you can use the -b
option to reference the binding file.
xjc -b binding.xml schema.xsd
Upvotes: 3