如何为xjc编写外部绑定文件?

tan*_*ens 16 java xml jaxb xjc

JAXB xjc的文档说:

-b指定要处理的一个或多个外部绑定文件.(每个绑定文件必须具有自己的"-b"开关.)外部绑定文件的语法非常灵活.您可能有一个包含多个模式自定义的绑定文件,或者您可以将自定义分解为多个绑定文件:

   xjc schema1.xsd schema2.xsd schema3.xsd -b bindings123.xjb

   xjc schema1.xsd schema2.xsd schema3.xsd 
         -b bindings1.xjb -b bindings2.xjb -b bindings3.xjb 
Run Code Online (Sandbox Code Playgroud)

此外,命令行上的模式文件和绑定文件的排序无关紧要.

但是,我在哪里可以找到这个"外部绑定文件"的文档?

Tim*_*ner 8

外部绑定文件记录在oracle.com 上的Customizing JAXB Bindings页面上

引用:

外部绑定自定义文件

通过包含绑定声明的外部文件对JAXB绑定进行的自定义采用如下所示的一般形式.

<jxb:bindings schemaLocation = "xs:anyURI">
   <jxb:bindings node = "xs:string">*
      <binding declaration>
   <jxb:bindings>
</jxb:bindings> 
Run Code Online (Sandbox Code Playgroud)

schemaLocation是对远程模式节点的URI引用,它是一个XPath 1.0表达式,用于标识与给定绑定声明关联的schemaLocation中的模式节点.例如,JAXB绑定声明文件中的第一个schemaLocation/node声明指定模式名称和根模式节点:

<jxb:bindings schemaLocation="po.xsd" node="/xs:schema"> 
Run Code Online (Sandbox Code Playgroud)

后面的schemaLocation/node声明,比如上面模式中名为ZipCodeType的simpleType元素,将采用以下形式:

<jxb:bindings node="//xs:simpleType[@name='ZipCodeType']"> 
Run Code Online (Sandbox Code Playgroud)

也可以看看; 在JAXB编译器选项


关于外部绑定文件的另一个很好的资源是oreilly.来自oreilly的示例绑定文件是:

引用:

清单11.使用外部绑定文件

<jxb:bindings version="1.0" 
  xmlns:jxb="http://java.sun.com/xml/ns/jaxb" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
  jxb:extensionBindingPrefixes="xjc">
    <jxb:bindings schemaLocation="po4.xsd" node="/xs:schema">
        <jxb:globalBindings>
            <xjc:superClass name="com.syh.Shape"/>
            <xjc:serializable uid="12343"/>
        </jxb:globalBindings>
        <jxb:bindings node="//xs:element[@name='Widgets']//xs:complexType//xs:choice">
            <jxb:property name="Shapes"/>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>
Run Code Online (Sandbox Code Playgroud)