[jdom-interest] The default namespace behaviour

Colin LeMahieu clemahieu at gmail.com
Tue Jun 6 18:59:42 PDT 2006


I'm thinking more along the lines of, the user types an XML file:
<easy xmlsn="short">
	<b>
		<c/>
	</b>
	<d>
		<e:f xmlns:e="weird">
			<g/>
		</e:f>
	</d>
</easy>

And I'm looking to convert it to:
<a:easy xmlns:a="ReallyLongNamespace">
	<b>
		<c/>
	</b>
	<d>
		<e:f xmlns:e="weird">
			<g/>
		</e:f>
	</d>
</a>

As I see it right now, with the current JDOM model there's no way to easily
just change the namespace of a and affect elements b, c, d, and g as it
should.

JDOM seems to have no concept of a default namespace other than perhaps the
document builder.  This seems to very much be erroneous.

Constructing the first XML example in memory with:
Element easy = new Element("easy", "short");
Element b = new Element("b");
Element c = new Element("c");
...
easy.addContent(b);
b.addContent(c);

constructs b and c with no namespace which is not as it should be.  My quote
earlier is from someone claiming that this is the correct behaviour, "if you
don't know what namespace an element is in, you don't know what element
you're creating"  I say it's incorrect, or otherwise tell me a way to do:

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

and have it affect b, c, d, and a possible g somewhere down the XML tree
that would inherit the default namespace from a.

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


-----Original Message-----
From: Bradley S. Huffman [mailto:hip at cs.okstate.edu] 
Sent: Tuesday, June 06, 2006 13:30
To: Colin LeMahieu
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] The default namespace behaviour 

"Colin LeMahieu" writes:

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

How about a custom JDOMFactory that overrides the element methods.

Brad



More information about the jdom-interest mailing list