Using JAXB to generate XML binding classes.
The schema is based on a set of legacy XML files, and includes this snippet:
<xs:complexType name="MetaType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="Name" />
<xs:attribute type="xs:string" name="Scheme" />
<xs:attribute type="xs:string" name="Value" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
The 'Value' attribute conflicts with the 'value' property of xs:string
, and the code generation fails with the error:
com.sun.istack.SAXParseException2: Property "Value" is already defined. Use <jaxb:property> to resolve this conflict.
Once after xxxx.xjb file is created for duplicate attribute name "value" (duplicate is default 'value' provided by JAXB) as below, run XJC command to create JAXB objects
xjc -p "com.track.doc" -d "C:\JAXBDocuments\prasam\Desktop\JAXB_me\DealerTrace" appSamp.xsd -b xxxx.xjb
appSmp.xsd:-
xxxx.xjb:-
you can also use the parameter -XautoNameResolution in the command line and also in the pluggin to let jxc resolve the name if you don´t bother about the name on the classes.
If you want to avoid creating/changing a JAXB bindings file, and you don't mind annotating your XSD, you can add the jxb:property annotation to your attribute's definition, e.g.:
with suitable additions to the xs:schema tag:
None of this bindings worked for me, i got this error:
It produced an empty target node... Then i realized (after 30 minutes of dispair) that my binding was aiming to a complexType instead of an element. The answer was in my xsd file.
Thank you
This bindings file mentioned in the other answer did not work for me with CXF 3.0.0. Notice that jaxb namespace has an element "bindings" and so do the namespace jaxws, so we need to declare them:
In my case the schema was already inside the WSDL so I did no have to specify the schemaLocation attribute.
The answer lies in making use of JAXB bindings (
site-template.xjb
):The XPath expressions locate the nodes and renames it, thereby avoiding the naming conflict.
Using this bindings XML file, the generated Java class ends up having the desired
getValueAttribute()
(as well as thegetValue()
).