xjc for only part of schema

2019-02-17 07:33发布

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.

1条回答
等我变得足够好
2楼-- · 2019-02-17 08:18

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
查看更多
登录 后发表回答