xjc for only part of schema(xjc 仅用于部分模式)
问题描述
我们计划使用 JAXB 将 xml 映射到对象.我们的要求是,我们将只处理文档的一部分(有点大),所以我们只想将该部分(片段)转换为对象.因此,我们不想为 xsd 中的所有元素创建类.
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.
我们如何要求 xjc 在生成类时忽略某些元素或考虑特定元素?
How can we ask xjc to ignore certain elements or consider specific elements while generating classes?
根据我的阅读,我们可以使用绑定文件来自定义 xjc 的行为,但是我们可以在模式中放置什么来忽略元素.
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.
推荐答案
您可以使用外部绑定文件将 XJC 配置为使用现有类而不是生成一个.您可以通过指向一个不存在的类来利用这一点,以使 JAXB 排除部分 XML 模式.在下面的示例中,不存在的类 com.example.Fake
将用于名为 Foo 的复杂类型.
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 通话
xjc -d outputDir -b binding.xml yourSchema.xsd
这篇关于xjc 仅用于部分模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:xjc 仅用于部分模式
基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01