[jdom-interest] The default namespace behaviour

Michael Kay mike at saxonica.com
Wed Jun 7 00:21:18 PDT 2006


If you want to change the name of every node in your document, it seems to
me entirely reasonable that you should have to visit every node in your
document.

This model is treating the inheritance of namespaces as something that
happens when a document tree is constructed from lexical XML. This is the
same as the XPath model, and it's entirely logical and consistent. The
alternative, of treating namespace inheritance as something that happens at
tree access time, gets you into the kind of horrible mess you see in DOM.

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: jdom-interest-bounces at jdom.org 
> [mailto:jdom-interest-bounces at jdom.org] On Behalf Of Colin LeMahieu
> Sent: 07 June 2006 03:00
> To: 'Bradley S. Huffman'
> Cc: jdom-interest at jdom.org
> Subject: RE: [jdom-interest] The default namespace behaviour 
> 
> 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
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@you
rhost.com



More information about the jdom-interest mailing list