[jdom-interest] How to read xml files with namespaces

Brian Trezise brian.trezise at intellidata.net
Thu Aug 6 09:08:48 PDT 2009

Ok, so I'm having trouble reading an XML file with a namespace.  I've been
hunting and searching for a solution for several hours now, and I can't
figure out what I'm doing wrong.


Heres a sample of the xml:


<?xml version="1.0"?>









                                    <dimension-name>Lead Length








                                    <dimension-name>Lead Length














There can be many <drawing> tags with the above contents, but there are no
other objects permitted as direct children of <drawings>.


I'm using the following code to read the xml file:


      File drawingXmlFile = new File(config.getDrawingXmlFile());

      SAXBuilder saxBuilder = new SAXBuilder();

      Document doc = saxBuilder.build(new BufferedInputStream(new


      Element rootElem = doc.getRootElement();

      List<Element> drawingElems = rootElem.getChildren("drawing");


drawingElems consistently comes back with size 0.  I have tried several
variations, including simply "rootElem.getChildren()" with no success.  I
know that the problem relates to namespaces in some way, because if I take
out the namespace from the root element of the xml, it just works.  However,
this solution is not ideal as this document is intended to be maintained by
somebody without a lot of experience in XML, so the validation provided by
using the namespace would be very helpful.


Can anybody give me any pointers as to what I'm doing wrong?

Thanks in advance,



Brian Trezise

IntelliData, Inc.

Staff Software Engineer

brian.trezise at intellidata.net

t: 720.524.4864

m: 303.809.9782


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090806/aad781f8/attachment.htm

More information about the jdom-interest mailing list