javaxsdjaxbjaxb2-maven-plugin

ATTRIBUTE GROUP - Property "Value" is already defined. Use <jaxb:property> to resolve this conflict


Problem statement

I have defined the following XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xc="XmlCache" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:import namespace="XmlCache" schemaLocation="mdml/com/mycompany/mds/mdml/schema/xc.xsd"/>
    <xs:element name="MarketData">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="xc:XmlCache" minOccurs="0" maxOccurs="1"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

The element xc:XmlCache is defined in the file mdml/com/mycompany/mds/mdml/schema/xc.xsd.

I want to generate Java classes based on this XSD, using jaxb (with plugin jaxb2-maven-plugin).

Error

I keep on getting the following error during compilation:

[ERROR] jar:file:/C:/Users/miannizzotto/.m2/repository/com/sun/xml/bind/jaxb-xjc/2.1.13/jaxb-xjc-2.1.13.jar!/com/sun/xml/xsom/impl/parser/datatypes.xsd[14,33] com.sun.istack.SAXParseException2; systemId: jar:file:/C:/Users/miannizzotto/.m2/repository/com/sun/xml/bind/jaxb-xjc/2.1.13/jaxb-xjc-2.1.13.jar!/com/sun/xml/xsom/impl/parser/datatypes.xsd; lineNumber: 14; columnNumber: 33; Property "Value" is already defined. Use <jaxb:property> to resolve this conflict.

followed by

[ERROR] file:/D:/v3.1.build.dev.asset.x.91253.5.4.dev/component/legacy/sdk/product-api/api/src/main/xsd/mdml/com/mycompany/mds/mdml/schema/xc.xsd[57,63] com.sun.istack.SAXParseException2; systemId: file:/D:/v3.1.build.dev.asset.x.91253.5.4.dev/component/legacy/sdk/product-api/api/src/main/xsd/mdml/com/mycompany/mds/mdml/schema/xc.xsd; lineNumber: 57; columnNumber: 63; The following location is relevant to the above er

Structure of the guilty file

The file mdml/com/mycompany/mds/mdml/schema/xc.xsd is very big but I will let below only the guilty part (line 57 and the main nodes of its tree):

<?xml version="1.0"?>
<!DOCTYPE xs:schema>
    ...
    <xs:attributeGroup name="valueAtt">
        <xs:attribute name="value" use="optional" form="qualified"/> <!--this is line 57-->
    </xs:attributeGroup>
    ...
</xs:schema>

What have I tried so far?

I have tried to play around with my binding file, but all of the below attempts still lead to the same error.

Attempt 1 (Inspired by this question and its answers)

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
               jaxb:extensionBindingPrefixes="xjc"
               jaxb:version="1.0">

    <jaxb:bindings schemaLocation="../xsd/MarketData.xsd" >

        <jaxb:bindings node=".//xs:attributeGroup[@name='valueAtt']">
            <jaxb:bindings node=".//xs:attribute[@name='value']">
                <jaxb:property name="ValueAttribute"/>
            </jaxb:bindings>
        </jaxb:bindings>

    </jaxb:bindings>
</jaxb:bindings>

(trying to get the node "valueAtt" of type "attributeGroup", then the node "value" of type "attribute", and rename it to "ValueAttribute".

Attempt 2 (Inspired by this question)

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
               jaxb:extensionBindingPrefixes="xjc"
               jaxb:version="1.0">

    <jaxb:bindings schemaLocation="../xsd/MarketData.xsd" >

        <jaxb:bindings node=".//xs:element[@name=MarketData]/xs:complexType/xs:sequence/xs:element[@ref=XmlCache]">
            <jaxb:bindings node=".//xs:attributeGroup[@name='valueAtt']">
                <jaxb:bindings node=".//xs:attribute[@name='value']">
                    <jaxb:property name="ValueAttribute"/>
                </jaxb:bindings>
            </jaxb:bindings>
        </jaxb:bindings>

    </jaxb:bindings>
</jaxb:bindings>

(The main difference with the previous attempt is that here I try to select the node XmlCache by reference using @ref, since the problem occurs into another XSD).

Attempt 3 (Inspired just by the intuition that the issue occurs into another XSD, that is just referenced in my XSD):

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
               jaxb:extensionBindingPrefixes="xjc"
               jaxb:version="1.0">

    <jaxb:bindings schemaLocation="../xsd/mdml/com/mycompany/mds/mdml/schema/xc.xsd"
    node="//xs:attributeGroup[@name=valueAtt]/xs:attribute[@name=value]">
        <jaxb:property name="ValueAttribute"/>
    </jaxb:bindings>
</jaxb:bindings>

What am I doing wrong? Can anyone please help?


Solution

  • Finally, the solution was the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
                   xmlns:xs="http://www.w3.org/2001/XMLSchema"
                   xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
                   jaxb:extensionBindingPrefixes="xjc"
                   jaxb:version="1.0">
    
        <jaxb:bindings schemaLocation="../xsd/mdml/com/mycompany/mds/mdml/schema/xc.xsd"
        node="//xs:attributeGroup[@name='valueAtt']/xs:attribute[@name='value']">
            <jaxb:property name="ValueAttribute"/>
        </jaxb:bindings>
    </jaxb:bindings>
    

    Basically it was my attempt 3, wrapping the names of the attributes around single quote.