I have the following XML string, I want to convert this string to org.w3c.dom.Document in order to get the value of 'CallPaySecureResult' element.
<?xml version="1.0" encoding="UTF-8"?>
<S:Body xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<ns2:CallPaySecureResponse xmlns:ns2="https://paysecure/merchant.soap/">
<CallPaySecureResult>&lt;status&gt;success&lt;/status&gt;&lt;errorcode&gt;0&lt;/errorcode&gt;&lt;errormsg /&gt;&lt;guid&gt;d785f819-6fc1-1c68-8edf-bbb65cba5412&lt;/guid&gt;&lt;/paysecure&gt;</CallPaySecureResult>
</ns2:CallPaySecureResponse>
</S:Body>
I have tried the following code
public String processIssuerResultParameters(String strXML)throws Exception
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
Document doc=null;
String CallPaySecureResult ="";
try
{
builder = factory.newDocumentBuilder();
doc = builder.parse( new InputSource( new StringReader( strXML ) ) );
logger.severe(doc.getTextContent());
} catch (Exception e) {
return "1:"+e.toString()+doc.getTextContent();
}
}
I have tried this:
InputSource is= new InputSource(new StringReader(strXML));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
builder = null;
builder = factory.newDocumentBuilder();
doc = builder.parse(is);
and this :
Source source = new StreamSource(new StringReader(strXML));
DOMResult result = new DOMResult();
TransformerFactory.newInstance().newTransformer().transform(source , result);
doc = (Document) result.getNode();
But in all the cases variable 'doc' is null.
How can I parse the XML(string) to Document and get the value in <CallPaySecureResult>?