users@jaxb.java.net

Re: [Issue 33] Unable to xjc XMLSchema.xsd

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Wed, 27 Oct 2004 11:29:07 +0200

Hi.

> I tried to add the comments to the issue directly, but could not figure
> out how...
>
> I looked over both links you provided. It does appear that the previous
> conversation was started by the same problem -- however, the XSOM
> solution won't work.
> I am not needing to parse random schemas; I am creating a GUI to
> generate JAXB-based XSDs. IE: the reason I was trying to parse the one
> from W3C (besides the fact that it is THE standard schema defining the
> XSD format; and besides the fact that JAXB should be able to handle any
> valid XSD) is so that I could get access to the setXXX methods without
> having to resort to either Xerces (which is really ugly to use) or JDOM
> (which I left for JAXB). It does not appear that XSOM is designed to
> allow me to GENERATE xsd files -- only to read them.
>
> Regardless of the reasons for wanting to use it; it seems obvious that
> it is a bug in JAXB if it can not handle an XSD released by W3C.

I could compile XMLSchema.

Steps to do this:

1. Download XMLSchema.xsd, XMLSchema.dtd and datatypes.dtd.
2. Comment out built-in types (lines 1307 - 2170).
3. Use the following external binding customization:

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                version="1.0">
   <jaxb:bindings schemaLocation="../schema/XMLSchema.xsd"
node="/xsd:schema">

     <jaxb:bindings node="/xsd:schema/xsd:element[@name='all']">
         <jaxb:class name="AllElement"/>
     </jaxb:bindings>

     <jaxb:bindings node="/xsd:schema/xsd:element[@name='attributeGroup']">
         <jaxb:class name="AttributeGroupElement"/>
     </jaxb:bindings>

     <jaxb:bindings node="/xsd:schema/xsd:element[@name='attribute']">
         <jaxb:class name="AttributeElement"/>
     </jaxb:bindings>

     <jaxb:bindings node="/xsd:schema/xsd:element[@name='simpleType']">
         <jaxb:class name="SimpleTypeElement"/>
     </jaxb:bindings>

     <jaxb:bindings node="/xsd:schema/xsd:element[@name='group']">
         <jaxb:class name="GroupElement"/>
     </jaxb:bindings>

     <jaxb:bindings node="/xsd:schema/xsd:element[@name='element']">
         <jaxb:class name="ElementElement"/>
     </jaxb:bindings>

     <jaxb:bindings node="/xsd:schema/xsd:element[@name='complexType']">
         <jaxb:class name="ComplexTypeElement"/>
     </jaxb:bindings>

     <jaxb:bindings
node="/xsd:schema/xsd:element[@name='restriction']/xsd:complexType">
         <jaxb:class name="RestrictionElementType"/>
     </jaxb:bindings>

   </jaxb:bindings>
</jaxb:bindings>

Et voila.

For a working example, see tests/xmlschema in HyperJAXB disrtibution
(http://hyperjaxb.dev.java.net) (the new distribution will be available
in an hour).

A small comment to step 2. Seems like JAXB/XJC include datatypes.xsd
implicitly. Therefore, when you import the XML schema itself, there is a
type name collision. My research shows there's currently no way to avoid
this except for commenting out the offending types.

Bye.
/lexi

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net