Antwort: RE: [jdom-interest] Namespace help

Ken Rune Helland kenh at csc.no
Thu Jul 25 07:56:27 PDT 2002


> That's why this whole thing is so confusing to me. Elliotte and Bob
> both said "" is not a namespace, you said "" is a namespace ...
> Furthermore, if level3 can inherit level2's namespace without a xmlns=,
> then why didn't level2 do so and inherit level1's namespace thus get
> rid of xmlns=""?
> 
> I guess my original question is still unclear. I'm not having any
> problem with namespace or the parser. All java objects I have, either a
> Document or an Element, are exactly correct. The issue is with the
> Outputter, when it's printing out a XML string why is it outputting
> 'xmlns=""' when it knows that <level2> is inheriting the namespace form
> <root_elem> which is in "http://my.com" namespace? 
> 

You must be carefull to to separate the XML text representation
from the JDOM object representation. A JDOM Element has exactly the
namspace that was given to the Element constructor. No mather where
you move it around in the tree or between documents it keeps this 
namespace, it DOES NOT inherit any namespace from it parent.

In the XML text representation it doesn not inherit the namespace
from the parent either but it inherits the namespace declartions.

Since <root_elem> declares the default namespace to be "http://my.com"
all children not explicitly in another namespace or redeclaring the
default namespace is also in the "http://my.com" namespace.

in the case of the example document:
<level1 xmlns="http://my.com">
  <level2 xmlns="" >




 









More information about the jdom-interest mailing list