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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With