[jdom-interest] Default Namespace vs No-Namespace.

Robert (Jamie) Munro rjmunro at arjam.net
Fri Jul 4 05:46:17 PDT 2003


> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of John Jefferson
> Sent: 03 July 2003 19:03
> To: Elliotte Rusty Harold
> Cc: 'jdom-interest at jdom.org'
> Subject: Re: [jdom-interest] Default Namespace vs No-Namespace.
>
>
> > >The default namespace is a feature of xml which
> > allows
> > >you to declare one namespace at the top and for any
> > >element in the document which is not given a
> > namespace
> > >that element will inherit the default namespace.
> >
> > No, this statement is not true. Namespaces are quite
> > a bit more
> > complicated than that. When  designing an API, it's
> > important to be
> > really precise and clear about these things.
>
>
> Maybe you can enlighten me on this point.  Or point me
> to something easier to digest than the xml namespace
> spec.
>
>
> > >Why is jdom's behavior set such that when I have a
> > >document and I set the default namespace at the
> > root
> > >the child nodes of the root do not inherit the
> > >namespace but instead are set to the special
> > >no-namespace namespace.
> >
> > Because that's what you asked for in your code.
>
> Alright how can I, without iterating through all nodes
> in the document, set the root element to have a
> default namespace and have that namespace propogate
> down to all children nodes which are not already
> namespaced - other than the special no-namespace?

You can't. It's like asking "How can I, without iterating through all the
nodes, change all the <A> tags to <B> tags?" Of course you have to iterate
through all the nodes.

The "Special no-namespace" is the namespace that all XML elements with no
declared namespace are in.

Bear in mind what a namespace is and what it is for. It is to enable you to
be sure that your elements names do not clash with other peoples. Two
elements called <A> in different namespaces are AS DIFFERENT (arguably more
different) than an element called <A> and an element called <B> from a
logical point of view. That is the whole point of namespaces.

Robert Munro




More information about the jdom-interest mailing list