users@jaxb.java.net

Re: custom binding for single element XML

From: Ryan Shoemaker - JavaSoft East <Ryan.Shoemaker_at_sun.com>
Date: Thu, 26 Jun 2003 17:13:29 -0400

Steve Maring wrote:

> I have an XML file like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <MY_ELEMENT>text</MY_ELEMENT>
>
>
> I'd like to have that bound to a classname of MyElement with a single
> property called Value.
>
> The XSD looks like this:
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:element name="MY_ELEMENT" type="xsd:string"/>
> </xsd:schema>
>
> I've tried this but it does not work:
>
> <jaxb:bindings version="1.0"
> xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <jaxb:bindings schemaLocation="MyElement.xsd" node="/xsd:schema">
> <jaxb:bindings node="//xsd:element[@name='MY_ELEMENT']">
> <jaxb:class name="MyElement"/>
> </jaxb:bindings>
> </jaxb:bindings>
> </jaxb:bindings>
>
>
> I keep ending up with a class named MY_ELEMENT!
>

Are you using JAXB 1.0? When I run your sample against 1.0.1, I get a
MYELEMENT.java without the customization, and a MyElement.java with it.

I seem to recall there were some bugs regarding the XML -> Java name
conversion in JAXB 1.0...

> Any thoughts would be greatly appreciated. I've got the complicated XML
> licked!
>

Congrats - you're a better person than I am ;8-)

--Ryan

> Steve Maring
> Tarpon Springs, FL
>