Get the value from a SOAP message in Java
15,916
Assuming you're using JDOM:
soap:Body is actually two parts: the namespace and the element name. You'll want to use the Namespace class to include that information when retrieving it.
Try doing something like:
envelopeNode.getChild("Body",envelopeNode.getNamespace());
That'll make it look for the child element with the name "Body", and the same namespace as the envelope node.
Related videos on Youtube
Author by
vs777
Updated on September 16, 2022Comments
-
vs777 over 1 year
I am getting a SOAP message as a string after making a call to the web service.
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <PassOracleXMLDataResponse xmlns="http://tempuri.org/"> <PassOracleXMLDataResult> <gesystem xmlns=""> <return_code>0</return_code> <message>PRS User does not exists in GETS</message> <invoiceid>TESTADDTLINFO2</invoiceid> <datetime>Apr 17 2013 4:19PM</datetime> </gesystem> </PassOracleXMLDataResult> </PassOracleXMLDataResponse> </soap:Body> </soap:Envelope>
I need to retrieve the values and elements. When I tried to use a simple SAXBuilder to build a Document and traverse it, I got an exception after trying to getChild on "soap: Body"
getChild("soap:Body") - returns null.
-
vs777 about 11 yearsThanks Peter, it worked. There is only one strange thing. When I was getting a child Element for "PassOracleXMLDataResult" it also required to provide a Namespace as a second parameter./n Namespace nmspc = Namespace.getNamespace("tempuri.org/"); Element parseResponse = bodyEm.getChild("PassOracleXMLDataResponse", nmspc); Element passResult = parseResponse.getChild("PassOracleXMLDataResult", nmspc);
-
aryn.galadar about 11 yearsRight; my example just uses the namespace of the parent element (in this case, "schemas.xmlsoap.org/soap/envelope". Since PassOracleXMLDataResponse is in a different namspace ("tempuri.org/"), you'd need to pass that one to getChild(), not the parents'.
-
lospejos almost 8 yearsI suppose this is because it need the full node identification, that contains namespaces too.