我使用JAXB绑定从现有的xml模式生成Java类。但是我想跳过以“ Old”结尾的类型的类生成,或者声明“ obsolete”属性或包含undescore的类型。
我徒劳地尝试修改我的JAXB绑定文件,但我不知道该写什么节点声明跳过了这些类型...
<!-- 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 -->
有解决方案吗?
最佳答案
假设您处理的所有类型都不引用这些“跳过的类型”,那么您可以使用外部绑定文件来指定它们与现有类相对应,从而不会生成新的类。如果引用了这些跳过的类型,则对该假类的引用将被带入模型。
绑定文件
<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>
完整的例子
Shared class for child element in JAXB in different xmls/roots