If you're working with the CDA XML
schema or one of it's derivatives like the Australian CDA Schema Extension
and trying to use xjc
to compile it into a set of usable Java
classes you may be hitting this error...
The issue comes from a name collision between an attribute and a child element within certain complex types in this schema. Specifically it is the id
element and the ID
attribute. The schema has something like this...
I would argue that the ID
attribute is of little value...
The purpose of the xs:ID datatype is to define unique identifiers that are global to a document and emulate the ID attribute type available in the XML DTDs.
This attribute can be used for referencing parts of a document within the document itself but has no real application outside of the document scope. However, the id
element has application outside of the scope of the document as well as within it. So since the ID
attribute is of little importance the solution is to rename it to something that will not cause a name collision.
Rather than modifying the XSD
itself, I like to use a bindings file to customise the output of xjc
. A binding file like the one below would allow xjc
to compile the schema successfully.
The bindings look for these ID
attributes on specific objects and rename them to 'id2'
. It's as simple as that.
Hope you found this post useful...
...so please read on! I love writing articles that provide beneficial information,
tips and examples to my readers. All information on my blog is provided free of
charge and I encourage you to share it as you wish. There is a small favour I ask in return however -
engage in comments below, provide feedback, and if you see mistakes let me know.
If you want to show additional support and help me pay for web hosting and
domain name registration,
donations, no matter how small, are always welcome!
Use of any information contained in this blog post/article is subject to this disclaimer
Other posts you may like...