JAXB 绑定自定义 [英] JAXB Binding Customization

查看:51
本文介绍了JAXB 绑定自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试从 xsd 生成类时,出现此错误:

While trying to generate classes from a xsd, i got this error:

java.lang.IllegalArgumentException: Illegal class inheritance loop.  Outer class OrderPropertyList may not subclass from inner class: OrderPropertyList

我的 xsd 定义了一个元素来对一个无界元素进行分组,如下所示:

My xsd define a element to group a unbounded element like this:

  <element minOccurs="0" name="orderPropertyList">
    <complexType>
      <sequence>
        <element maxOccurs="unbounded" name="orderProperty" type="tns:orderProperty" />
      </sequence>
    </complexType>
  </element>

我的自定义绑定如下此页面,但它不起作用.这是我的绑定:

And my customization binding follows as specified on this page, but it doesn´t work. Here my binding:

<jaxb:bindings schemaLocation="../xsd/Schema.xsd" node="/xs:schema">
    <jaxb:bindings node="//xs:element[@name='orderPropertyList']">
        <jaxb:class name="OrderPropertyList"/>
    </jaxb:bindings>
</jaxb:bindings>

我的目的是为 orderPropertyList 生成一个单独的类,而不是在 xsd 的根元素内生成内部类的默认行为.

My intention is to generate a individual class for orderPropertyList, not the default behave that is generating a inner class inside the root element of the xsd.

我曾在这里看过一个有同样意图的人这里,但它对我来说不能正常工作.:(

I´ve watched someone with the same intention here and here, but it doesn´t work properly for me. :(

JAXB 版本:

Specification-Version: 2.1
Implementation-Version: 2.1.8

有什么帮助吗?

推荐答案

我相信你需要设置的是:

I believe what you need to to is set:

<jaxb:globalBindings localScoping="toplevel"/>

这将生成独立类而不是嵌套类.

This will generate standalone classes instead of nested classes.

<jaxb:bindings schemaLocation="../xsd/Schema.xsd" node="/xs:schema">
    <jaxb:bindings node="//xs:element[@name='orderPropertyList']">
            <jaxb:class name="OrderPropertyList"/>
    </jaxb:bindings>
</jaxb:bindings>

是一个冗余绑定,因为 orderPropertyList 将默认映射到 OrderPropertyList.包的名称包括默认情况下嵌套在其中的外部类名称,因此您无需更改.

is a redundant binding, since orderPropertyList will map by default to OrderPropertyList. The name of the package includes the outer class name it is nested in by default, so you're not changing that.

此外,如果您确实想更改生成的类的名称,我认为 XPath 实际上应该是:

Also, if you did want to change the name of the generated class, I think the XPath would actually be:

<jaxb:bindings node="//xs:element[@name='orderPropertyList']/xs:complexType">

以 complexType 结尾.我认为排除这一点是导致您收到错误消息的原因.

with complexType on the end. I think excluding this was what was causing the error message you got.

这篇关于JAXB 绑定自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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