Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write an external binding file for xjc?

Tags:

java

xml

jaxb

xjc

The documentation of JAXB xjc says:

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

like image 837
tangens Avatar asked Nov 10 '09 12:11

tangens


People also ask

What is JAXB binding file?

JAXB stands for Java Architecture for XML Binding.

What is XJB file?

Full format name of files that use XJB extension is OEPE JAXB Wizard Bindings. OEPE JAXB Wizard Bindings format was developed by Oracle Corporation. XJB files are supported by software applications available for devices running Windows. Files with XJB extension are categorized as Developer Files files.

Is XJC a JAXB?

Use the JAXB schema compiler, xjc command to generate JAXB-annotated Java classes. The schema compiler is located in the app_server_root \bin\ directory. The schema compiler produces a set of packages containing Java source files and JAXB property files depending on the binding options used for compilation.

How do I create a Java class using XJC?

Open a command prompt. Run the JAXB schema compiler, xjc command from the directory where the schema file is located. The xjc schema compiler tool is located in the app_server_root \bin\ directory. Use the generated JAXB objects within a Java application to manipulate XML content through the generated JAXB classes.


1 Answers

The external binding file is documented on the Customizing JAXB Bindings page on oracle.com

Quote:

External Binding Customization Files

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

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']"> 

See also; the JAXB Compiler Options


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

Quote:

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>
like image 90
Tim Penner Avatar answered Sep 28 '22 18:09

Tim Penner