[jdom-interest] Accessor methods and namespaces

Laurent Bihanic laurent.bihanic at atosorigin.com
Mon Aug 12 06:01:04 PDT 2002


keallen at mail.stic.net wrote:
>    The biggest one concerns the use of namespaces in the various accessor
> methods of element.  My document uses a default namespace, and only one, so
> all elements are part of that namespace.  Since getChild(String) interprets
> the lack of a namespace as being NO namespace, I have to specify the
> namespace whenever I get a child.  This seemed very cumbersome - I ducked
> it by creating a Namespace with the document's default namespace that I use
> in all my "gets".  It works, but seems like it would fall apart quickly if
> my document had multiple namespaces.

You could use:
    current.getChild("foo", current.getNamespace())

This could let you explore subtrees where all elements belong to the same 
namespace. You'll just have to woory about namespaces when looking for the 
root of a subtree.

Laurent




More information about the jdom-interest mailing list