[jdom-interest] Some background on JDOM Namespaces

philip.nelson at omniresources.com philip.nelson at omniresources.com
Mon Apr 2 22:10:14 PDT 2001

This text could be useful somewhere 

The JDOM namespace api reflects what the namespace *is* rather than how the
namespace appears in text.  This fits with the JDOM goal of keeping JDOM
elements and attributes as standalone entities.  It works just as if you
looked at the textual representation and said to yourself, "that element is
in this namespace because of the prefix which is declared there" or "that
element is in that namespace because it's a child of this element with that
default namespace".  In either case, textually, you can see what the
namespace of the child is from the context and relate to it that way.  JDOM
namespaces are at the level where you have already interpreted them.  JDOM
has already figured out what the namespace really is and that is what you
work with.  As a result, a default namespace in JDOM means nothing, because
the actual namespace of any element or attribute is determined when they are
created rather than where they are created in the JDOM tree.  

The uniqueness and magic of the JDOM namespace api is that it does not have
to keep namespace declarations.  Instead of having the context of
surrounding elements matter in a JDOM document, this magic occurs when
serializing.  When serializing, relatively simple list traversals happen and
based on context, namespace declarations appear as needed.

Since the namespace of each element and attribute has already been
determined by the time it is created, there is no concept of a default
namespace or of elements returning children from a particular namespace
because of namespaces that the element may be aware of.  In JDOM, if you
want an element or attribute from a particular namespace, specify the
namespace you mean or you will get children in the empty namespace.
getChild("name") means exactly the same thing as getChild("name",

More information about the jdom-interest mailing list