users@jaxb.java.net

[jaxb2] Namespace and other questions

From: Spies, Brennan <Brennan.Spies_at_ejgallo.com>
Date: Tue, 3 Apr 2007 17:10:59 -0700

Hi,

 

I am new to JAXB (the latest, 2.1.2) and trying to use it to
marshall/unmarshall XML elements (sub-trees) to and from an in-memory DOM.
Sorry if I am asking anything very obvious, but I am a "newbie" here...

 

My (simplified) XML structure looks like:

 

<jmx-configuration xmlns="mynamespace" elementFormDefault="qualified">

            <connection name="id-name">

                        <!-bound element -->

                        <websphere>

                                    <!-sub-elements here...-->

                        </websphere>

            </connection>

            <connection name="id-name2">

                        <remote-api>

                        </remote-api>

            </connection>

</jmx-configuration>

 

The <websphere> and <remote-api> are the elements that are being bound by
JAXB.

 

I am using annotations on existing classes to do marshalling/unmarshalling.
Something like

 

@XmlRootElement(name="websphere" namespace="mynamespace")

@XmlAccessor(XmlAccessType.NONE)

@XmlType(name="wasConfig", propOrder={...})

 

I am getting close to what I want, but not quite...

 

1) XmlAccessType.PROPERTY or XmlAccessType.PUBLIC_MEMBER give me errors
complaining of duplicates...the runtime would complain that I had duplicates
such as "location" and "getLocation()". Why? I had to switch to
XmlAccessType.NONE and annotate each field member individually.

2) When marshalling to <websphere> or <remote-api> elements, JAXB would
set the default namespace to null and then set that element to the namespace
I had declared in the annotation, like

 

<ns4:websphere xmlns="" xmlns:ns4="mynamespace">

 

...even though the default namespace for all of the DOM is "mynamespace".
Playing around with "##default" didn't help.

 

3) The behavior in #2 caused all of the child elements of <websphere> or
<remote-api> to have null namespaces. I had to manually set the 'namespace'
attribute on the individual @XmlElement annotations in order to set the
namespace correctly. Is there a way to simply do this at the class level?

4) I am not able to customize the namespace prefix using a custom
NamespacePrefixMapper class (following the example under /examples in the
distro). It generates "ns4" every time...

 

Thanks,

 

Brennan