0

I am using Jquery. I have an xml returned from a webservice. So I want to extract some value from it.

This is an xml example returned from webservice:

<ns3:ExecuteResponse xmlns:ns3="http://www.opengis.net/wps/1.0.0"
  xmlns:ns1="http://www.opengis.net/ows/1.1"
  xmlns:ns2="http://www.w3.org/1999/xlink"
  statusLocation="http://webservice:9090/b57c-43b8-40b2-8e09-4d6489df55be"
  serviceInstance="http://xyz.it:9090/services/http-post"
  version="1.0.0" service="XXX">
  <ns3:Process ns3:processVersion="0.2">
    <ns1:Identifier>OM_BIOCLIM</ns1:Identifier>
    <ns1:Title xml:lang="en-US">Bioclim</ns1:Title>
    <ns1:Abstract xml:lang="en-US">abcdefghi</ns1:Abstract>
  </ns3:Process>
  <ns3:Status creationTime="2010-07-07T10:42:05.768+02:00">
    <ns3:ProcessAccepted>ProcessConfiguration has been
    accepted.</ns3:ProcessAccepted>
  </ns3:Status>
  <ns3:ProcessOutputs />
</ns3:ExecuteResponse>

So this is my code:

    $.ajax({
      type: 'POST',
      url: "php/geoproxy.php?url=http://www.abc.it:9090/1.0.0-service/services/http-post",//wpsUrl,
          contentType: "text/xml",
      data: xmlRequest,
      dataType: "text/xml",
      success: function(xml){

        var xmlDoc;                             
        if (window.DOMParser)
          {
          parser=new DOMParser();
          xmlDoc=parser.parseFromString(xml,"text/xml");
          }
        else // Internet Explorer
          {
          xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
          xmlDoc.async="false";
          xmlDoc.loadXML(xml);
          } 

            //extract statusLocation attribute
        },
    error: function(XMLHttpRequest, textStatus, errorThrown) { 
      alert("error "+XMLHttpRequest); 
    } 
});

How I can extract the statusLocation attribute of ns3:ExecuteResponse node?

Thanks a lot.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
michele
  • 26,348
  • 30
  • 111
  • 168
  • possible duplicate of [\[jQuery\] Parsing xml](http://stackoverflow.com/questions/3187819/jquery-parsing-xml) – Tim Down Jul 07 '10 at 09:57
  • 1
    You've already asked this, and received a correct answer. As pointed out to you, you don't need to parse the XML: if you use `"xml"` as the dataType, you will receive an XML document in the `success` callback. – Tim Down Jul 07 '10 at 09:57
  • Even if you insist on parsing the xml yourself, the answer has been given to you in the other question anyway: `xmlDoc.documentElement.getAttribute("statusLocation")`. – Crescent Fresh Jul 07 '10 at 10:09
  • possible duplicate of [jQuery XML parsing with namespaces](http://stackoverflow.com/questions/853740/jquery-xml-parsing-with-namespaces) – Shikiryu Apr 11 '13 at 13:54

1 Answers1

1

you can do it so much simpler than that

 success: function(xml){
       statusLocation = $(xml).attr('statusLocation')
 }

and not use ActiveX controls

TheBrain
  • 5,528
  • 2
  • 25
  • 26