1

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?

wjans
  • 10,009
  • 5
  • 32
  • 43
mahonya
  • 9,247
  • 7
  • 39
  • 68

3 Answers3

1

It seems that your XMLSchema is not valid. Have you tried to validate it against an XML processing tool (such as Notepad++ with XML plugins or XmlSpy)?

Fernando Miguélez
  • 11,196
  • 6
  • 36
  • 54
  • My xml schema is http://www.w3.org/2001/XMLSchema.xsd THE xml schema for xml schema from w3. I doubt that it has validity issues. People have reported success, see the link I've given. With Java 6 and the xml schema at the address I've given, I am seeing the error I've included in the question. – mahonya Jul 18 '11 at 16:11
0

I've experienced same problem with JAXB 2.1.10. It seems that is known issue with JAXB in Java 6. Using the following JAXB bindings file solved the problem:

<?xml version="1.0" encoding="UTF-8"?>
<!-- bindings.xml -->
<jaxb:bindings 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jaxb:extensionBindingPrefixes="xjc"
    version="2.1">

    <jaxb:bindings schemaLocation="XMLSchema.xsd" node="//xs:element[@name='schema']/xs:complexType/xs:complexContent/xs:extension/xs:sequence[1]">
        <jaxb:property name="SchemaElements"/>
    </jaxb:bindings>
</jaxb:bindings>

Output:

$ls
XMLSchema.dtd  XMLSchema.xsd  bindings.xml  datatypes.dtd  src  xml.xsd

$xjc -version
xjc version "JAXB 2.1.10 in JDK 6"
JavaTM Architecture for XML Binding(JAXB) Reference Implementation, (build JAXB 2.1.10 in JDK 6)

$xjc -p com.example.document.xsd -d src -extension -b bindings.xml XMLSchema.xsd
parsing a schema...
compiling a schema...
com\example\document\xsd\All.java
com\example\document\xsd\Annotated.java
com\example\document\xsd\Annotation.java
Stanislav Mamontov
  • 1,734
  • 15
  • 21
0

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 -extension flag 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.

Community
  • 1
  • 1
Keith Layne
  • 3,688
  • 1
  • 24
  • 28