2

I have the following xsd (I only post the relevant part here but the command was run against this excerpt, too)

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
    <xs:complexType name="OptionType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute type="xs:string" name="name" use="optional"/>
                <xs:attribute type="xs:string" name="value" use="optional"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:complexType name="ControllableType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute type="xs:float" name="value" use="optional"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
</xs:schema>

I run the following command against it:

xjc src/main/resources/session.xsd -p org.myorg.mypackage -d src/main/java/org/myorg/mypackage

I get the following error:

[ERROR] Property "Value" is already defined. Use &lt;jaxb:property> to resolve this conflict.
line 39 of jar:file:/usr/lib/jvm/java-8-openjdk-amd64/lib/tools.jar!/com/sun/xml/internal/xsom/impl/parser/datatypes.xsd

[ERROR] The following location is relevant to the above error
line 14 of file:/home/user/project/src/main/resources/session.xsd

[ERROR] Property "Value" is already defined. Use &lt;jaxb:property> to resolve this conflict.
line 39 of jar:file:/usr/lib/jvm/java-8-openjdk-amd64/lib/tools.jar!/com/sun/xml/internal/xsom/impl/parser/datatypes.xsd

[ERROR] The following location is relevant to the above error
line 7 of file:/home/user/project/src/main/resources/session.xsd

Failed to parse a schema.

I read something about bindings here:

Symbol is already defined. Use JAXB property to resolve the conflict

JAXB Compiling Issue - [ERROR] Property "Any" is already defined

But why is this even needed? Isn't the attribute fully qualified and unique by XML element name combined with the attribute name?

Like "OptionType.value" or "ControllableType.value"

dfsg76
  • 504
  • 1
  • 6
  • 22

2 Answers2

4

The problem is that you have a complex type with simple content and an attribute value:

<xs:complexType name="ControllableType">
    <xs:simpleContent>
        <xs:extension base="xs:string">
            <xs:attribute type="xs:float" name="value" use="optional"/>
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>

This would allow something like

<somelement value="1.5">one and a half</somelement>

XJC tries to create two properties:

  • one for the attribute value,
  • one for the simple content.

First property is named value by default because this is the name of the attribute.

Second property is named value by default because this is the default name for simple content properties.

This gets you a collision.

lexicore
  • 42,748
  • 17
  • 132
  • 221
1

It looks like you are trying to extend java.lang.String. But since the String class already contains a "value" attribute you can't use that in your child classes.-

I imagine one could overlook that the String class is final and therefore can't be extended. When you rename your "value" attribute you will see that xjc will work, but it still won't extend String in the generated code (since it's not possible), but xjc apparently still checks if your attribute names are valid which causes the problem.

@lexicore explained in the comments why this assumption is wrong:


EDIT considering lexicores comments

So your options are to rename your "value". Check @lexicores answer for the reason why.

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xs:complexType name="OptionType">
    <xs:simpleContent>
        <xs:extension base="xs:string">
            <xs:attribute type="xs:string" name="name" use="optional"/>
            <xs:attribute type="xs:string" name="my_value" use="optional"/>
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>
<xs:complexType name="ControllableType">
    <xs:simpleContent>
        <xs:extension base="xs:string">
            <xs:attribute type="xs:float" name="my_value" use="optional"/>
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>

or not to use an xs:extension within xs:simpleContent.

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xs:complexType name="OptionType">
    <xs:attribute type="xs:string" name="name" use="optional"/>
    <xs:attribute type="xs:string" name="value" use="optional"/>
</xs:complexType>
<xs:complexType name="ControllableType">
    <xs:attribute type="xs:float" name="value" use="optional"/>
</xs:complexType>

giro
  • 421
  • 1
  • 7
  • 19
  • No, it's not about extending `java.lang.String` (which is not possible anyway). – lexicore Aug 21 '17 at 09:00
  • So what is doing then? – giro Aug 21 '17 at 09:09
  • It defines base type for the simple content of complex type. You wrote *It looks like you are trying to extend `java.lang.String`.* which is not what's happening here. – lexicore Aug 21 '17 at 09:11
  • Cool. I didn't get that at first. So would I edit my answer or delete it since it's wrong? – giro Aug 21 '17 at 09:20
  • I'd just add a note in bold that the answer is apparently not correct. If you delete it or not is up to you. Edit it if you want and feel that my answer is not sufficient. – lexicore Aug 21 '17 at 09:29