Xjc only for part of the circuit

We plan to use JAXB to map xml to objects. Our requirement is that we will work with only one part of the document (a little biggie), so we only want to convert this part (fragment) into objects. Therefore, we do not want to create classes for all elements in xsd.

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

From what I read, we can use the bindings file to customize the behavior of xjc, but what can we put in the circuit to ignore the elements.

+6
source share
1 answer

You can use an external binding file to configure XJC to use an existing class instead of creating it. You can use this by pointing to a nonexistent class to force JAXB to exclude parts of your XML schema. The following example nonexistent class com.example.Fake be used for 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 challenge

 xjc -d outputDir -b binding.xml yourSchema.xsd 
+2
source

All Articles