TL;DR
<jaxb:typeName prefix="Hi_"/>
corresponds to the classes generated from named complex types. You could do the following by adding <jaxb:elementName prefix="Hi_"/>
to affect the classes generated from global elements:
<?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>
Full Example
Below is a complete example.
schema.xsd
The schema below has a global element and a named complex type.
<?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 Call
xjc -b binding.xml schema.xsd
Output
We see that the class corresponding to the global element was prefixed with Element_
and the class corresponding to the named complex type was prefixed with Type
. ObjectFactory
and package-info
are not part of the domain model and are leveraged by JAXB for metadata so their names were not affected.
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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…