I need to process types and their relationships in an XSD (find all concrete types descending from an abstract type etc)
This page claims it is possible via JAXB: http://www.antonioshome.net/blog/2009/20091012-1.php but I am receiving an error with the xjc that comes with Java 6. The error is:
[ERROR] Element "{http://www.w3.org/2001/XMLSchema}annotation" shows up in more
than one properties.
line 248 of file:/C:/tmp/xsdProcessing/XMLSchema.xsd
[ERROR] The following location is relevant to the above error
line 242 of file:/C:/tmp/xsdProcessing/XMLSchema.xsd
I’ve seen references to the problem, but I have not seen any clear explanations for the source of the problem or the solution.
So as of today, is it possible to use JAXB to work on the xml schema for xml schema? If not, what would be the alternative? How does JAXB process schemas to create Java objects?
Yes, you can get it to work with xjc. The issue you are experiencing is the first of two hurdles I came across when solving this problem.
I’m not entirely clear about the source of the problem, but the solution is the “simpler and better binding” extension present in the JAXB RI. It is described here somewhat and in some other old blog posts by Kohsuke Kawaguchi that I can’t find right now.
You should have success if you use the
-extensionflag when you run xjc and a binding file similar to the one in my answer to another question (the second issue I faced when trying to compile XMLSchema.xsd).To be fair, I haven’t actually tried to (un)marshall any XML that imports XML Schema yet, so there may be more issues that I haven’t encountered yet.