[jdom-interest] The default namespace behaviour

Colin LeMahieu clemahieu at gmail.com
Tue Jun 6 22:37:31 PDT 2006


I was hoping to mimic the behavior that XML files have.  When using the
default namespace, all un-prefixed sub elements are within that namespace.

 

<a xmlns="one">

  <b/>

  <c/>

</a>

 

The b and c tags are in the "one" namespace.

 

If I changed this to:

<a xmlns="two">

  <b/>

  <c/>

</a>

 

The b and c tags are in the "two" namespace.  I made one small change to a
and got a side-effect of changing b and c; this is how it works with written
XML documents.

 

If I parsed the first example and generated a JDOM model and called
a.setNamespace(Namespace.getNamespace("two")) and then spit the file out,
what I would have, essentially, is:

<a xmlns="two">

  <b xmlns="one"/>

  <c xmlns="one"/>

</a>

 

This doesn't fit the XML idea that, if you change the parent's namespace,
un-prefixed children will implicitly change their namespace.

 

----------------

Colin LeMahieu

Phone: 408-499-5269

Fax: 267-989-4575

Email: clemahieu at gmail.com

 

I strongly disagree with your sense that:

a.setNamespace(namespace.getNamespace("ReallyLongNamespace"));

 

should set the namespace for all child elements that use the same default
namespace as a. This would be a big leap for JDOM to make. Since it's
entirely legitimate to have different default namespaces at different
levels, having JDOM guess which ones you wanted to change would invariably
be incorrect (in other words, what if I really wanted setNamespace() to just
set that element's namespace). Writing the getDescendents()-using code above
or even better, as Mr. Huffman suggested, a custom JDOMFactory would be the
best way to go about explictingly specifying what transformation you wanted
to do. 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20060607/03630cc3/attachment.htm


More information about the jdom-interest mailing list