[jdom-interest] First pass at Namespace revision[eg]

Jason Hunter jhunter at collab.net
Thu Mar 29 21:35:01 PST 2001

philip.nelson at omniresources.com wrote:
> Yes and no :-) Yes, I think that JDOM is doing what it intended to do,
> though I didn't at the time I wrote this. No, it's not doing what I think it
> possibly should do.

Philip, I think we're increasingly on the same page with this but I want
to write out my thoughts on the matter to make sure.

I think the name "default namespace" probably causes some confusion.  It
helps to understand the JDOM model if you recognize the default
namespace is nothing but a simple no-prefix namespace, to be used by
elements which in a textual representation have no explicit namespace
prefix.  It's not a special namespace designed for being inherited any
more than any other namespace.  And because of this, it's not
appropriate for an element constructed explictitly not in a namespace
(not just without a namespace prefix in the textual rep) to change its
namespace URI because of where it's added in the document.

> What I think the problem is lies in the difference between the object model
> and the textual representation.  

Yes, somewhat.  Initially (as you probably remember Philip) we had JDOM
namespaces modeled directly after the textual rep and namespaces were
100% inherited from parents.  Then Elliotte (author of O'Reilly's "XML
in a Nutshell" and IDG's "XML Bible" for those who don't know him) made
the point that namespaces are intrinsic to an element's identity, and we
changed models.

> even if the element was in
> the default namespace of an ancestor

That phrase doesn't make much sense if you recognize that a namespace
URI or lack thereof is intrinsic to an element.  You may be have the
same namespace URI as an ancestor (and therefore be in the same
namespace), or you may not be.  But you aren't really ever in the
default namespace of an ancestor.

> Changing the default namespace of an entire tree is very simple because you
> only have to change it in one place.  

Why should it be any different to change the URI associated with the
empty-string prefix than to change the URI associated with the "x"
string prefix?

> No change to current api where fully
> qualified namespaces are used.  An explicit empty namespace is treated
> exactly like a qualified namespace, which it should be (through an
> EMPTY_NAMESPACE or similar construct).  NO_NAMESPACE means *only* "no
> explicit namespace specified".

NO_NAMESPACE means the element is in no namespace.  That's semantically
identical to it having a namespace prefix of "" and a URI of "", per the
namespaces spec.

> as illustrated by
> <element xmlns="urn:foo">
>   <child />
> </element>

You construct this with:

Namespace foo = Namespace.getNamespace("", urn:foo");
new Element("element", foo)
  .addContent(new Element("child", foo));

> <element xmlns="urn:foo">
>   <child xmlns="" />
> </element>

You construct this with:

Namespace foo = Namespace.getNamespace("", urn:foo");
new Element("element", foo))
  .addContent(new Element("child"));

> I like the NO_NAMESPACE as opposed to null also.  For similar reasons I like

There's no semantic difference though, at least from what I understand.


More information about the jdom-interest mailing list