users@jaxb.java.net

cannot specify xmlns on a child element with an annotation

From: anil <anilksharma_at_btinternet.com>
Date: Wed, 16 Sep 2009 09:32:35 -0700 (PDT)

Hi -

I'm new to JAXB so please forgive me if this is a stupid question.

I'm generating some XML from an object graph and I need to explicitly set
the xmlns value on a child element of the DOM document I create. For
instance:

<foo:rootElement xmlns:foo="http://www.abc.com"
                        xmlns:baa="http://www.xyz">
  <foo:child1>
    <baa:child2 xmlns:baa="http://www.xyz">
       <baa:child3 />
    </baa:child2>
  </foo:child1>
</foo:rootElement>

As you can see the child2 element has an xmlns explicitly set. I've tried
trying to do this with the @XmlAttribute annotation, but that gives me a DOM
exception:

org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or
change an object in a way which is incorrect with regard to namespaces.

The only way I have found to be able to do what I want to do is to get a DOM
representation by marshalling the object graph into a Document, and then
using:

element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:baa",
"http://www.xyz");

which works, but it s a bit messy.

Could anyone give me some advice as to whether this is possible to do with
an annotation?

Many thanks in advance,
Anil.

-- 
View this message in context: http://www.nabble.com/cannot-specify-xmlns-on-a-child-element-with-an-annotation-tp25476021p25476021.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.