Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xjc for only part of schema

We plan to use JAXB for mapping of xml to objects. Our requirement is such that we will be working on only one part of the document (slightly biggish), so we want to only convert that part (a fragment) to objects. Hence, we do not want to create classes for all the elements in the xsd.

How can we ask xjc to ignore certain elements or consider specific elements while generating classes?

From what I have read, we can use bindings file to customize the behaviour of xjc, but what can we put in schema for ignoring elements.

like image 339
OKOK Avatar asked May 06 '14 06:05

OKOK


1 Answers

You can use an external binding file to configure XJC to use an existing class instead of generating one. You can leverage this by pointing to a non-existant class to get JAXB to exclude parts of your XML Schema. In the example below the non-existant class com.example.Fake will be used for the complex type named Foo.

binding.xml

<jxb:bindings schemaLocation="yourSchema.xsd">
    <jxb:bindings node="//xs:complexType[@name='Foo']">
        <jxb:class ref="com.example.Fake"/>
    </jxb:bindings>
</jxb:bindings>

XJC Call

xjc  -d outputDir -b binding.xml yourSchema.xsd
like image 119
bdoughan Avatar answered Oct 18 '22 10:10

bdoughan