[jdom-interest] NamesSpace questions

Chad LaJoie clajoie at vt.edu
Mon Mar 19 10:28:09 PST 2001

I was wondering if some one could give me some clarification on how 
namespaces are used in JDOM.  My experience so far seems to indicate that 
if you declare ANY namespace that you lose the ability to have a default 
name space.  Let me give an example

         <dc:creator>some text</dc:creator>

To read this I've tried the following code:

   Element root = doc.getRootElement();
   Element elem = root.getChild("channel");

This fails because it can't find the creator (because it's in a different 
namespace I assume), so then I tried this

   Namespace dc = Namespace.getNamespace("dc", 
   Element root = doc.getRootElement();
   Element elem = root.getChild("channel");
   elem.getChildText("creator", dc);

This failed because it now couldn't find the channel element.

So how do namespaces work?  I was under the impression that anything with 
out a explicit namespace listed was in the default namespace and could be 
gotten to by any of the convenience methods that don't require the a 
namespace parameter.  Could some please clear up this is supposed to 
work?  Thanks.

Chad La Joie                           "Only a man who can not conquer
IT Specialist                             his deficiencies feels the need to
IS&C - WARD                             convince the world he has none"

More information about the jdom-interest mailing list