Search code examples
eclipsexpathbindingjaxbxbrl

JAXB binding XBRL element does not work


I am trying to generate localised XBRL classes with JAXB in Eclipse, but I have been getting an error:

[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

As the error suggests, an element and an attribute name conflicts. These are lines 145 and 151:

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

So I'd need to rename either (or both). This is what I've been trying to do - bind the element title to 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>

This produces the following error, plus the original "title already defined" errors:

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

Suggestions to get it working?

EDIT: as helderdarocha suggested, my expression was wrong. I am new to XML and XPath, and it was a bit confusing since the element does not have the "xs:" namespace typed excplicitly. After I fixed that error, I got another one:

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

As all the "ref" attributes need to be updated, I put the tag "multiple='true'" in the binding. Now I am getting the following error, and cannot figure out how to solve it:

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

Ideas for this? I do want to bind the contents in the attribute 'ref' for the element in question to another name.


Solution

  • I solved the problem after all by applying these SO questions:
    JAXB fails to generate Java classes for XBRL
    JAXB XJC Two declarations cause a collision. Customized binding cannot be honored

    So after I solved the original problem, I had additional problems with objectfactory collisions, which I fixed as well. This is how my working bindings.xjb looks in general:

    <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>
    

    I hope this helps other XBRL/XML/JAXB newcomers to get started.