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