Advertisement

08.15.2007 at 08:49AM PDT, ID: 22764540
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

Help parsing an XML response from a SOAP server

Asked by sspachtholz in Extensible Markup Language (XML), JavaScript

Tags: , , , ,

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--------

<html>
<head>
<script language="javascript">

function makeSoapRequest(form){
      // create the payload of the SOAP request
      var soapData = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://XXXXX/jboss-net/services/sylantro/auth" xmlns:intf="http://XXXXX/jboss-net/services/sylantro/auth" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://webapi.sylantro.com/webapi" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> \n' +
            '<SOAP-ENV:Body> \n' +
            '<mns:loginUser xmlns:mns="http://XXXXX/jboss-net/services/sylantro/auth" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> \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';
            //alert(soapData);

      try{
            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
      }catch (e) {
            //alert("Permission UniversalBrowserRead denied.");
      };

      try{
            if (window.XMLHttpRequest){
            req = new XMLHttpRequest();
      }else{
            req = new ActiveXObject("Microsoft.XMLHTTP");
      }
      }catch(e){
 
      };
 
      req.open("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");
      req.send(soapData);
      
      document.getElementById('response').innerHTML = req.responseText;
             var xmlDocument1 = req.responseXML;
      parseXmlDocument(xmlDocument1);
}


function parseXmlDocument(docName){

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

      alert(xmlDoc.DocumentElement.firstchild;);
      var tokencode = xmlDoc.DocumentElement.firstchild;

};

</script>
</head>
<body>

<FORM NAME="myform" ACTION="" METHOD="GET">
      <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)">
</FORM>

<br><hr><br>

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

</body>
</html>


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

  <?xml version="1.0" encoding="UTF-8" ?>
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <soapenv:Body>
- <ns1:loginUserResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://XXXXX/jboss-net/services/sylantro/auth">
- <loginUserReturn xsi:type="ns2:AuthenticationInfo" xmlns:ns2="http://webapi.sylantro.com/webapi">
  <locale xsi:type="xsd:string">en</locale>
  <token xsi:type="xsd:string">61813599c32032fa5cb3c24f6ab74902b1c41d257b0fc97494f7a91028731eb52fef368934b412cd3b7f49fbe47877f8f7f072e7d37609abc5bc3c2c3b6981cc4d2f6e0789d6341e3a8d0d875e5a5773ebca32dda25298a</token>
  <userType xsi:type="xsd:int">1</userType>
  </loginUserReturn>
  </ns1:loginUserResponse>
  </soapenv:Body>
  </soapenv:Envelope>Start Free Trial
[+][-]08.15.2007 at 09:18AM PDT, ID: 19701059

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.15.2007 at 10:27AM PDT, ID: 19701810

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Extensible Markup Language (XML), JavaScript
Tags: javascript, soap, response, xml, parse
Sign Up Now!
Solution Provided By: flipz
Participating Experts: 2
Solution Grade: A
 
 
[+][-]08.15.2007 at 10:28AM PDT, ID: 19701819

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.15.2007 at 10:39AM PDT, ID: 19701954

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.15.2007 at 10:42AM PDT, ID: 19702000

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.15.2007 at 10:47AM PDT, ID: 19702066

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628