users@jaxb.java.net

Re: custom binding for single element XML

From: Steve Maring <steve_at_maring.org>
Date: Fri, 27 Jun 2003 11:29:47 -0400

I've confirmed, with RI 1.0.1, that I can bind a "Global Element" [spec
ref 6.7.3.4], which appears to be defined as an Element containing a
complexType, to a custom class name. The default binding behavior is for
an Element containing a simpleType to be bound to a property of the
containing complexType. However, there seems to be special handling when
a simpleType Element is actually the root element and thus has no
complexType container. This behavior is to bind the Element name as the
interface (class) name and allow the modification of it's value as a
property called Value.

I guess I have two questions on this end:

1) Can a simpleType Element contained in a complexType be forced to bind
to a class containing a Value property instead of being bound to a
property of the containing complexType? Can I also bind an XML attribute
to a class containing a Value property?

2) How do I customize the class name for the case where a simpleType
Element is the root Element?


Cheers.
Steve Maring


> 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
>>
>