xjc 仅用于部分模式 [英] xjc for only part of schema

查看:38
本文介绍了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 仅用于部分模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆