Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Generating Top Level Classes</strong></p> <blockquote> <p>I want get just Records class and separate Contract class.</p> </blockquote> <p>By default a JAXB implementation will generate classes corresponding to anonymous complex types as static inner classes. If you want everything to be a top level class you can as you stated in your question use the following external binding customization:</p> <pre><code>&lt;jaxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1"&gt; &lt;jaxb:globalBindings localScoping="toplevel"/&gt; &lt;/jaxb:bindings&gt; </code></pre> <hr> <p><strong>Resolving Name Conflicts</strong></p> <blockquote> <p>I get error:</p> </blockquote> <pre><code>org.xml.sax.SAXParseException: A class/interface with the same name "com.my.package.Text </code></pre> <p>One of the purposes of the static inner classes is to prevent name conflicts. With all top level classes you can use an external binding file to rename the class generated from a complex type. Below is an example where the class corresponding to the complex type itemType would be generated as Item.</p> <pre><code>&lt;jaxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1"&gt; &lt;jaxb:globalBindings localScoping="toplevel"/&gt; &lt;jaxb:bindings schemaLocation="company.xsd"&gt; &lt;jaxb:bindings node="//xsd:element[@name='employee']/xsd:complexType/xsd:sequence/xsd:element[@name='address']/xsd:complexType"&gt; &lt;jaxb:class name="EmployeeAddress"/&gt; &lt;/jaxb:bindings&gt; &lt;/jaxb:bindings&gt; &lt;/jaxb:bindings&gt; </code></pre> <hr> <p><strong>Using the Binding File</strong></p> <p>You specify the binding file in the XJC call using the -b flag</p> <pre><code>xjc -b binding.xml your-schema.xsd </code></pre> <hr> <p><strong>For More Information</strong></p> <ul> <li><a href="http://blog.bdoughan.com/2011/07/jaxb-xjc-and-nested-classes.html" rel="nofollow">http://blog.bdoughan.com/2011/07/jaxb-xjc-and-nested-classes.html</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload