简体   繁体   中英

How to skip complexType in JAXB bindings

I use JAXB bindings to generate java class from an existing xml schema. But I want to skip class generation for types that endswith "Old" or declare an "obsolete" attribute or contains undescore.

I try, in vain, to modify my JAXB bindings file but I don't know what node write to declare these types skipped...

<!-- skip old types -->
<!-- with ie:obsolete attribute -->
<jaxb:bindings schemaLocation="external/insee/*.xsd">
<jaxb:bindings node="//*[@ie:obsolete='true']">
    <!-- declare this type skipped -->
</jaxb:bindings>
</jaxb:bindings>
<!-- that endswith Old -->
<!-- that contains "_" underscore -->

Is there a solution?

Assuming none of the types you process reference these "skipped types", then you could use an external bindings file to specify that they correspond to an existing class so that a new one won't be generated. If these skipped types are referenced then references to this fake class will be brought into your model.

binding.xml

<jxb:bindings 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    version="2.1">

    <jxb:bindings schemaLocation="beta.xsd">
        <jxb:bindings node="//xs:element[@name='person']/complexType">
            <jxb:class ref="com.FakeClass"/>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

Full Example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM