[jdom-interest] Default namespaces

Brian Barnett brian at calcxml.com
Tue Dec 16 20:43:47 PST 2008

I am not understanding how to use default namespaces with JDOM. Seeing
strange behavior. Here is a sample XML:

<litleResponse version="4.1" xmlns="http://www.litle.com/schema"
response="0" message="Valid Format" litleSessionId="2734282201">
	<batchResponse id="20081216211506" litleBatchId="2734282300"
		<authorizationResponse reportGroup="BWB" customerId="88673">

And here is some java code that loads it:

SAXBuilder builder = new SAXBuilder();
File inFile = new File("some-file.xml");
Document xmlResponseDoc = builder.build(inFile);
Element rootResponseElem = xmlResponseDoc.getRootElement();

Now, after loading this document, I can read the attributes of the
<litleResponse> element just fine using
rootResponseElem.getAttributeValue(). However, if I try to get the
<batchResponse> element using the code below, null is returned:

Element elem = rootResponseElem.getChild("batchResponse");

I think it has something to do with the xmlns="http://www.litle.com/schema"
attribute because I had trouble with it as part of the request as well.

What is the "best practice" for handling default namespaces in JDOM as
specified in the above xml example?


Brian Barnett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20081216/c0652a55/attachment.htm

More information about the jdom-interest mailing list