troubleshooting Question

Help parsing an XML response from a SOAP server

Avatar of sspachtholz
sspachtholz asked on
6 Comments1 Solution8269 ViewsLast Modified:
I've created a page that now sends off a proper request to a SOAP server and gets a response back.  The SOAP request is to log into the system.  The response has a token code in the XML that I need to use in all subsequent requests.

Today, the page displays the entire response as text on the web page.  What I need to do next is parse the response and store the token as a variable.

I've read some online tutorials and tried to hack together some code.  But its just not working.  

In the code below, the submit button calls the makeSoapRequest() function.  That function then calls the parseXMLDocument() function.  This new parseXMLDocument() function is where I am having problems.

Any assistance would be greatly appreciated.

----Here is the code for the page--------

<script language="javascript">

function makeSoapRequest(form){
      // create the payload of the SOAP request
      var soapData = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="" xmlns:apachesoap="" xmlns:impl="http://XXXXX/jboss-net/services/sylantro/auth" xmlns:intf="http://XXXXX/jboss-net/services/sylantro/auth" xmlns:soapenc="" xmlns:tns1="" xmlns:wsdl="" xmlns:wsdlsoap="" xmlns:xsd="" xmlns:xsi=""> \n' +
            '<SOAP-ENV:Body> \n' +
            '<mns:loginUser xmlns:mns="http://XXXXX/jboss-net/services/sylantro/auth" SOAP-ENV:encodingStyle=""> \n' +
            '<in0 xsi:type="tns1:EULoginRequest"> \n' +
            '<applicationName xsi:type="xsd:string">USERPORTAL</applicationName> \n' +
            '<tenantName xsi:type="xsd:string" /> \n' +
            '<userName xsi:type="xsd:string">' + form.username.value + '</userName> \n' +
            '<userPassword xsi:type="xsd:string">' + form.password.value  + '</userPassword> \n' +
            '</in0> \n' +
            '</mns:loginUser> \n' +
            '</SOAP-ENV:Body> \n' +
            '</SOAP-ENV:Envelope> \n';

      }catch (e) {
            //alert("Permission UniversalBrowserRead denied.");

            if (window.XMLHttpRequest){
            req = new XMLHttpRequest();
            req = new ActiveXObject("Microsoft.XMLHTTP");
      };"POST", "http://XXXXX/jboss-net/services/sylantro/auth", false);
      req.setRequestHeader("Content-Length", soapData.length);
      req.setRequestHeader("Content-Type", "text/xml");
      req.setRequestHeader("Soapaction", "sylantro/auth");
      document.getElementById('response').innerHTML = req.responseText;
             var xmlDocument1 = req.responseXML;

function parseXmlDocument(docName){

      var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async = "false";

      var tokencode = xmlDoc.DocumentElement.firstchild;



      <p>Username: <INPUT TYPE="text" NAME="username" VALUE=""></p>
      <p>Password: <INPUT TYPE="text" NAME="password" VALUE=""></p>
      <INPUT TYPE="button" NAME="submit" Value="Submit" onClick="makeSoapRequest(this.form)">


<div align="left">
      <span id="response"></span>


----This is what the SOAP response looks like that I need to parse-----

  <?xml version="1.0" encoding="UTF-8" ?>
- <soapenv:Envelope xmlns:soapenv="" xmlns:xsd="" xmlns:xsi="">
- <soapenv:Body>
- <ns1:loginUserResponse soapenv:encodingStyle="" xmlns:ns1="http://XXXXX/jboss-net/services/sylantro/auth">
- <loginUserReturn xsi:type="ns2:AuthenticationInfo" xmlns:ns2="">
  <locale xsi:type="xsd:string">en</locale>
  <token xsi:type="xsd:string">61813599c32032fa5cb3c24f6ab74902b1c41d257b0fc97494f7a91028731eb52fef368934b412cd3b7f49fbe47877f8f7f072e7d37609abc5bc3c2c3b6981cc4d2f6e0789d6341e3a8d0d875e5a5773ebca32dda25298a</token>
  <userType xsi:type="xsd:int">1</userType>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros