【问题标题】:JAXB binding XBRL element does not workJAXB 绑定 XBRL 元素不起作用
【发布时间】:2014-07-01 20:12:49
【问题描述】:

我正在尝试在 Eclipse 中使用 JAXB 生成本地化的 XBRL 类,但我遇到了一个错误:

[ERROR] Property "Title" is already defined. Use <jaxb:property> to resolve this conflict. 
line 145 of http://www.xbrl.org/2003/xl-2003-12-31.xsd

[ERROR] The following location is relevant to the above error
line 151 of http://www.xbrl.org/2003/xl-2003-12-31.xsd

正如错误提示的那样,元素和属性名称冲突。这些是第 145 和 151 行:

<element ref="xl:title" minOccurs="0" maxOccurs="unbounded" />
<attribute ref="xlink:title" use="optional" />

所以我需要重命名其中一个(或两个)。这就是我一直在尝试做的 - 将元素标题绑定到 titleElement:

<jxb:bindings version="1.0"
  xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xl="http://www.xbrl.org/2003/XLink" 
  schemaLocation="http://www.xbrl.org/2003/xl-2003-12-31.xsd">
    <jxb:bindings node="//element[@ref='xl:title']">
        <jxb:property ref="xl:titleElement"/>
    </jxb:bindings>
</jxb:bindings>

这会产生以下错误,加上原来的“标题已定义”错误:

[ERROR] XPath evaluation of "//element[@ref='xl:title']" results in empty target node
line 6 of titleElementAttributeFixer.xjb

建议让它发挥作用?

编辑:正如helderdarocha 所建议的,我的表达是错误的。我是 XML 和 XPath 的新手,这有点令人困惑,因为该元素没有明确键入的“xs:”命名空间。在我修复了那个错误之后,我又得到了一个:

[ERROR] XPath evaluation of "//xs:element[@ref='xl:title']" results in too many (3) target nodes

由于所有“ref”属性都需要更新,我将标签“multiple='true'”放在绑定中。现在我收到以下错误,不知道如何解决:

[ERROR] cvc-complex-type.3.2.2: Attribute 'ref' is not allowed to appear in element 'jxb:property'.

对此有什么想法?我确实想将相关元素的属性“ref”中的内容绑定到另一个名称。

【问题讨论】:

    标签: eclipse xpath binding jaxb xbrl


    【解决方案1】:

    我毕竟通过应用这些 SO 问题解决了这个问题:
    JAXB fails to generate Java classes for XBRL
    JAXB XJC Two declarations cause a collision. Customized binding cannot be honored

    所以在我解决了最初的问题之后,我还遇到了关于对象工厂冲突的其他问题,我也修复了这些问题。这就是我的工作 bindings.xjb 的一般外观:

    <bindings xmlns="http://java.sun.com/xml/ns/jaxb"
    xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    version="2.1">
    
        <bindings schemaLocation="http://www.xbrl.org/2003/xl-2003-12-31.xsd" 
            node="//xsd:schema//xsd:element[@name='title']">
            <property name="xlTitle"/>
        </bindings>
    
        <bindings schemaLocation="<local_dimension_file_D002>.xsd"
            node="//xsd:schema//xsd:element[@name='AcceleratedDepreciation']"> 
            <factoryMethod name="AcceleratedDepreciationD002"/>
        </bindings>
    
        ...many more objectfactory collisions solved...
    </bindings>
    

    我希望这有助于其他 XBRL/XML/JAXB 新手入门。

    【讨论】:

    • 你还有对象工厂冲突部分吗?你能分享一下吗?尝试用 xjc 解析 xbrl
    【解决方案2】:

    您的 XPath 表达式不正确。您的绑定 XML 声明了一个 xs 前缀来限定所有 XML Schema 元素,但是您的 XPath 表达式试图从无命名空间中找到一个 element 元素,因为它没有限定。

    你应该使用:

    <jxb:bindings node="//xs:element[@ref='xl:title']">
        <jxb:property ref="xl:titleElement"/>
    </jxb:bindings>
    

    【讨论】:

    • 解决了原来的问题,但是架构仍然无法解析,因为我面临另一个问题。你对此有什么想法吗?
    猜你喜欢
    • 2013-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多