JAXB issue: XMLTransform name typeName prefix not working

I want to convert some schemas to Java code. The schemes are all the same; for example, each has a TXLife root object. It would be easier to manage the code if each circuit generated code with unique class names. I can use the package binding to put the code from each circuit into my own package, but when I try to use the prefix binding to change the class names, it ignores it.

Here is my schema_bindings.xml file:

<? xml version = "1.0" encoding = "UTF-8"?>
<jaxb: bindings xmlns: jaxb = "http://java.sun.com/xml/ns/jaxb" xmlns: xsd = "http://www.w3.org/2001/XMLSchema" jaxb: version = "2.0 ">
   <jaxb: bindings schemaLocation = "schemas / HI_Request.xsd" node = "/ xsd: schema">
      <jaxb: schemaBindings>
         <jaxb: package name = "com.mycompany.hi" />
         <jaxb: nameXmlTransform>
            <jaxb: typeName prefix = "Hi _" />
         </ jaxb: nameXmlTransform>
      </ jaxb: schemaBindings>
   </ jaxb: bindings>
</ jaxb: bindings> 

When I run the xjc command, I get (I had to change the class path inside the xjc.bat file to make it work):

C: \ test> \ progs \ Java \ jaxb-ri-2.2.7 \ bin \ xjc.bat -extension -d src -b schema_bindings.xml schemas

parsing a schema ...
compiling a schema ...
com \ mycompany \ hi \ Holding.java
com \ mycompany \ hi \ InquiryLevel.java
com \ mycompany \ hi \ KeyedValue.java
com \ mycompany \ hi \ OLifE.java
com \ mycompany \ hi \ ObjectFactory.java
com\mycompany\hi\Policy.java
com\mycompany\hi\TXLife.java
com\mycompany\hi\TXLifeRequest.java
com\mycompany\hi\TransMode.java
com\mycompany\hi\TransSubType.java
com\mycompany\hi\TransType.java

, java ( ) "Hi_ < > ". Jaxb, , "". . , Ant xjc, .

, , , , , , .

+1
1

TL; DR

<jaxb:typeName prefix="Hi_"/> , . , <jaxb:elementName prefix="Hi_"/>, , :

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" jaxb:version="2.0">
   <jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
      <jaxb:schemaBindings>
         <jaxb:package name="com.mycompany.hi"/>
         <jaxb:nameXmlTransform>
            <jaxb:typeName prefix="Hi_"/>
            <jaxb:elementName prefix="Hi_"/>
         </jaxb:nameXmlTransform>
      </jaxb:schemaBindings>
   </jaxb:bindings>
</jaxb:bindings> 

.

schema.xsd

.

<?xml version="1.0" encoding="UTF-8"?>
<schema 
    xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.example.org/schema" 
    xmlns:tns="http://www.example.org/schema" 
    elementFormDefault="qualified">

    <element name="GlobalElement">
        <complexType>
            <sequence>
                <element name="foo" type="string"/>
            </sequence>
        </complexType>
    </element>

    <complexType name="NamedComplexType">
        <sequence>
            <element name="bar" type="string" />
        </sequence>
    </complexType>

</schema>

binding.xml

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" jaxb:version="2.0">
   <jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
      <jaxb:schemaBindings>
         <jaxb:package name="com.mycompany.hi"/>
         <jaxb:nameXmlTransform>
            <jaxb:typeName prefix="Type_"/>
            <jaxb:elementName prefix="Element_"/>
         </jaxb:nameXmlTransform>
      </jaxb:schemaBindings>
   </jaxb:bindings>
</jaxb:bindings> 

XJC

xjc -b binding.xml schema.xsd

, , , Element_, , , Type. ObjectFactory package-info JAXB , .

parsing a schema...
compiling a schema...
com/mycompany/hi/Element_GlobalElement.java
com/mycompany/hi/ObjectFactory.java
com/mycompany/hi/Type_NamedComplexType.java
com/mycompany/hi/package-info.java
+5

All Articles