I'm utilizing Javascript to interact with a SOAP webservice. Through firebug, I can confirm that the request has been successful and I am able to view the XML SOAP response.
How can I showcase this response on the webpage? Or even better - is there a way to display a specific node within the XML SOAP response? I had considered using XPath, but it doesn't seem to be functioning as expected.
Below is the code snippet:
<html>
<head>
<title>SOAP Client Test</title>
<script type="text/javascript">
function soap() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'https://mysoapurl.com', true);
// Construct SOAP request
var sr =
'<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' +
'<s:Header> ' +
'<USERNAME xmlns="http://www.tempuri.org">MyUsername</USERNAME>' +
'<PASSWORD xmlns="http://www.tempuri.org">MyPassword</PASSWORD>' +
'</s:Header>' +
'<s:Body>' +
'<GetData>Foo</GetData>' +
'</s:Body>' +
'</s:Envelope>';
// Send the POST request
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.setRequestHeader('SOAPAction', 'http://tempuri.org/MySoapActionURL');
xmlhttp.send(sr);
// The following XPath query should fetch the <GetResponse> element from the SOAP XML Response
var query = "//ns1:GetResponse[1]";
// Object defining namespaces in the query
var namespaceMapping = {
ns1: "http://tempuri.org/", // SOAP namespace
diffgr: "urn:schemas-microsoft-com" // service-specific namespace
};
// Extract the <GetResponse> element from the response document
var responseNode=XML.getNode(XMLHttpRequest.responseXML, query, namespaceMapping);
return responseNode;
}
window.onload = soap;
</script>
</head>
<body>
</body>
<html>
Your assistance would be highly appreciated. Thank you for your attention.