18

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 

此外,命令行中模式文件和绑定文件的顺序无关紧要。

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

4

1 回答 1

9

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

引用:

外部绑定自定义文件

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

<jxb:bindings schemaLocation = "xs:anyURI">
   <jxb:bindings node = "xs:string">*
      <binding declaration>
   <jxb:bindings>
</jxb:bindings> 

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

<jxb:bindings schemaLocation="po.xsd" node="/xs:schema"> 

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

<jxb:bindings node="//xs:simpleType[@name='ZipCodeType']"> 

也可以看看; 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>
于 2016-03-25T21:39:03.220 回答