title: Parsing XML from SOAP response with jQuery/JavaScript
body: <p>I have problems parsing response from SOAP sever with jQuery. I want to convert XML response to array because there are multiple rows of data as you can see below.</p>
  
  <p>This is request:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;soap:Body&gt;
      &lt;GetWorkPos xmlns="http://localhost/apps"&gt;
        &lt;id&gt;int&lt;/id&gt;
      &lt;/GetWorkPos&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>And this is response:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;soap:Body&gt;
      &lt;GetWorkPosResponse xmlns="http://localhost.com/apps"&gt;
        &lt;GetWorkPosResult&gt;
          &lt;GetWorkPos&gt;
            &lt;ProductId&gt;string&lt;/ProductId&gt;
            &lt;Product&gt;string&lt;/Product&gt;
            &lt;quantity&gt;decimal&lt;/quantity&gt;
            &lt;Em&gt;string&lt;/Em&gt;
            &lt;type&gt;string&lt;/type&gt;
          &lt;/GetWorkPos&gt;
          &lt;GetWorkPos&gt;
            &lt;ProductId&gt;string&lt;/ProductId&gt;
            &lt;Product&gt;string&lt;/Product&gt;
            &lt;Quantity&gt;decimal&lt;/Quantity&gt;
            &lt;Em&gt;string&lt;/Em&gt;
            &lt;Type&gt;string&lt;/Type&gt;
          &lt;/GetWorkPos&gt;
        &lt;/GetWorkPosResult&gt;
      &lt;/GetWorkPosResponse&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>And this is my code:</p>
  
  <pre><code>   $(document).ready(function () {
     $("#send").click(function (event) {
              var wsUrl = "http://localhost/Service.asmx";
  
              var soapRequest =
              '&lt;?xml version="1.0" encoding="utf-8"?&gt; \
              &lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
                  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt; \
                &lt;soap:Body&gt; \
                  &lt;GetWorkPos xmlns="http://localhost.com/apps"&gt; \
                    &lt;id&gt;' + $("#id").val() + '&lt;/id&gt; \
                  &lt;/GetWorkPos&gt; \
                &lt;/soap:Body&gt; \
              &lt;/soap:Envelope&gt;';
  
              console.log(soapRequest);
  
              $.ajax({
                  type: "post",
                  url: wsUrl,
                  contentType: "text/xml",
                  dataType: "xml",
                  data: soapRequest,
                  success: processSuccess,
                  error: processError
              });
  
          });
      });
  
      function processSuccess(data, status, req, xml, xmlHttpRequest, responseXML) {
          $(req.responseXML)
          .find('GetWorkPosResult')
          .each(function(){
              var id = $(this).find('ProductId').text();
              console.log(id);
          });
      }
  
      function processError(data, status, req) {
          alert(req.responseText + " " + status);
          console.log(data);
          console.log(status);
          console.log(req);
      }  
  </code></pre>