[jdom-interest] The default namespace behaviour

Colin LeMahieu clemahieu at gmail.com
Tue Jun 6 10:50:40 PDT 2006


I've been using JDOM in a tool I'm writing and I've come across a
peculiarity that I'm wondering if someone could clarify.  I believe this
issue has been talked about before however I wasn't able to find an answer
as to the direction JDOM took.

>From what it seems, JDOM throws away the idea of namespace inheritance once
the document is in memory, correct me if I'm wrong.  If I have elements:
<one xmlns="nsone">
	<two/>
		<three/>
	<two/>
	<two/>
</one>

Once I have this document in memory, if I change the namespace for the <one>
tag to "nsnew", the tags two and three will still be in namespace "nsone"

I found this response earlier in the mailing list:

> > > Yes, and that's a good thing. The URI should be passed into each
> > > element construction. It is a fundamental property of an element
> > > (which may be null or perhaps the empty string on occasion). If you
> > > don't have a URI, you don't have a complete element. If you don't
> > > know what the URI is, you don't know what kind of element you're
> > > creating. No tree walking is necessary. Either a URI is specified or
> > > the element is in the default namespace. Changing or setting this
> > > after element construction is no more necessary or useful than
> > > changing the element's name.

I'm wondering if anything was changed that I'm missing or if there's an easy
solution to my problem.

Essentially my problem is that I have a lot of longhand names and namespaces
and a user will only pick a subset of them to use in a particular document.
I would like to allow shorthand names in different namespaces and then
translate them to the longhand forms.  The document would then be processed
further.

My problem is that I don't know the structure of the element I'm renaming
and I don't think I should have to.  If proper inheritance was used the
element should be able to rename itself.  Is there a simple way to do this
renaming or will I have to recursively descend in to each element, check the
namespace and rename accordingly; this probably wouldn't be too hard to
implement but it would seem this would be a useful addition to your JDOM
tool.


----------------
Colin LeMahieu
Phone: 408-499-5269
Fax: 267-989-4575
Email: clemahieu at gmail.com




More information about the jdom-interest mailing list