jaxb-tools
jaxb-tools copied to clipboard
Cannot rename attribute in XSD
I am trying to generate Java classes from our XSD and we have a duplicate attribute name in schema file http://schemas.opengis.net/gml/3.2.1/gmlBase.xsd
On line 79 there is an attribute with name "owns" which appears to be duplicated (or maybe this schema is imported several times, dunno. Tried using episodes without success).
I tried to rename it using bindings
<jaxb:bindings schemaLocation="http://schemas.opengis.net/gml/3.2.1/gmlBase.xsd" node="/xs:schema">
<jaxb:bindings>
<jaxb:nameXmlTransform>
<jaxb:elementName suffix="Element" />
</jaxb:nameXmlTransform>
<jaxb:bindings node="//xs:attributeGroup[@name='OwnershipAttributeGroup']/xs:attribute[@name='owns']" >
<jaxb:property name="OwnershipAttributeGroupOwns"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
The result is that 'owns' is renamed to OwnershipAttributeGroupOwns and that is also duplicated.
Are you aware of https://github.com/highsource/ogc-schemas?
The result is that 'owns' is renamed to OwnershipAttributeGroupOwns and that is also duplicated.
Not sure I understand. You rename the attribute using bindings and it gets renamed as you specify. What is the problem then?
The problem is that the original problem of duplicate naming is not resolved.
Duplicated where?
That is a very good question because XJC does not specify where just that 'owns' already exists and that I should resolve that with bindings.
I suspect that the same XSD is imported several times on different locations. How does jaxb resolve this? Does it generate classes all over again or not?
Before we go on, my question is: how is this related to maven-jaxb2-plugin? Because right now this thread seems like general JAXB consulting.
Normally XJC logs where the collision occurs.
If the same XSD is imported in several locations, it is effectively processed just once. There are cases, however where the same XSD is imported differently (say, once via the absolute URL and once via relative). XJC has a bug related to this. The only effective workaround is to patch schemas and fix import URLs.
I've just check in ogc-schemas, I had no problem with this owns attribute, didn't have to customize anything.