[jdom-interest] Namespace help

Ken Rune Helland kenh at csc.no
Thu Jul 25 07:20:28 PDT 2002


>> > but XMLOutputter is giving this:
>> > 
>> > ===============
>> > ===============
>> > <root_elem xmlns="http://my.com" ....>
>> > 	<level2 xmlns="">
>> > 		<level3>xyz</level3>
>> > 	</level2>
>> > </root_elem>
>> > ===============
>> > 
>> > Notice <level3> is perfectly fine without any namespace? 
>> Please tell me what I'm missing here.
>> 
>> Right, because <level2> and <level3> are both not in namespaces, and
>> semantically, that's what this document says.
>> 
> 
> 
> So why didn't it print <level3 xmlns=""> just like <level2> then?

Becuse the xmlns="" set the DEFAULT namespace to "no namespace".
Unless a new default namespace is declared deeper in the tree all
children without an explicit namespace is in this namespace.

Note that the root element declares the default namespace to be
"http://my.com" so if the children had not stated xmlns="" they
woud implicitly be in the "http://my.com" namespace

IF the namespace of the root had been an explicit namespace and the
default namespace left as "no namespace" you woud not have to 
redeclare the default namespace:

<MyNS:root_elem xmlns:MyNS="http://my.com" ....>
 	<level2 >
 		<level3>xyz</level3>
 	</level2>
</root_elem>

Here the root_elem is explicitly in the "http://my.com" namespace
and and no default namepace is declared so all children not 
explicitly declaring a namspace or defult namespace are i "no namespace".


KenR





More information about the jdom-interest mailing list