« Return to Thread: Default namespaces

Default namespaces

by ooper01 :: Rate this Message:

Reply to Author | View in Thread

Default namespaces

Hi,
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" merchantId="044700">
                <authorizationResponse reportGroup="BWB" customerId="88673">
                        <litleTxnId>271178391204</litleTxnId>
                        <orderId>20081216-2115-88673</orderId>
                        <response>000</response>
                        <responseTime>2008-12-17T04:15:06</responseTime>
                        <message>Approved</message>
                        <authCode>11111</authCode>
                        <fraudResult>
                                <avsResult>01</avsResult>
                        </fraudResult>
                </authorizationResponse>
        </batchResponse>
</litleResponse>

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?

Thanks,

Brian Barnett


_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

 « Return to Thread: Default namespaces