如何为xjc编写外部绑定文件? [英] How to write an external binding file for xjc?

查看:72
本文介绍了如何为xjc编写外部绑定文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JAXB xjc 的文档说:

The documentation of JAXB xjc says:

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

-b Specify one or more external binding files to process. (Each binding file must have it's own "-b" switch.) The syntax of the external binding files is extremely flexible. You may have a single binding file that contains customizations for multiple schemas or you can break the customizations into multiple bindings files:

   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 

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

In addition, the ordering of the schema files and binding files on the command line does not matter.

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

But where do I find a documentation of this "external binding file"?

推荐答案

外部绑定文件记录在报价:

外部绑定自定义文件

External Binding Customization Files

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

Customizations to JAXB bindings made by means of an external file containing binding declarations take the general form shown below.

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

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

schemaLocation is a URI reference to the remote schema node is an XPath 1.0 expression that identifies the schema node within schemaLocation to which the given binding declaration is associated. For example, the first schemaLocation/node declaration in a JAXB binding declarations file specifies the schema name and the root schema node:

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

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

A subsequent schemaLocation/node declaration, say for a simpleType element named ZipCodeType in the above schema, would take the form:

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

另请参见; JAXB编译器选项

另一个有关外部绑定文件的信息的好资源是礼来.来自 oreilly 是:

Another good resource for information on the external binding file is oreilly. An example binding file from oreilly is:

报价:

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

Listing 11. Using An External Binding File

<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>

这篇关于如何为xjc编写外部绑定文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆