views:

53

answers:

3

Hi, I have this xml file:

    Response: <ns3:ExecuteResponse xmlns:ns3="http://www.opengis.net/wps/1.0.0" xmlns:ns1="net/ows/1.1" xmlns:ns2="http://www.w3.org/1999/xlink" statusLocation="xxxxf62" serviceInstance="http:/http-post" version="1.0.0" service="xxx">
<ns3:Process ns3:processVersion="0.2">
<ns1:Identifier>OM_B</ns1:Identifier>
<ns1:Title xml:lang="en-US">Bioclim</ns1:Title>
<ns1:Abstract xml:lang="en-US">yyyyyyyyyyyyyyyy</ns1:Abstract>
</ns3:Process>
<ns3:Status creationTime="2010-07-06T17:38:13.355+02:00">
<ns3:ProcessAccepted>ProcessConfiguration has been accepted.</ns3:ProcessAccepted>
</ns3:Status>
<ns3:ProcessOutputs />
</ns3:ExecuteResponse>

How I can extract statusLocation attribute in ExecuteResponse node?

Thanks a lot.

+1  A: 

Have you received this XML file via an XMLHttpRequest? If so, you can use its responseXML property.

alert(xhr.responseXML.documentElement.getAttribute("statusLocation"));

Or with jQuery:

$.ajax({
    type: "GET",
    url: "yourfile.xml",
    dataType: "xml",
    success: function(xml) {
        alert(xml.documentElement.getAttribute("statusLocation"));
    }
});
Tim Down
A: 
<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://service/publisher/35a17532-fe19-4c77-8a01-043eafc270c7" serviceInstance="http://services/http-post" version="1.0.0" service="yyy">
<ns3:Process ns3:processVersion="0.2">
<ns1:Identifier>OM_B</ns1:Identifier>
<ns1:Title xml:lang="en-US">Bioclim</ns1:Title>
<ns1:Abstract xml:lang="en-US"></ns1:Abstract>
</ns3:Process>
<ns3:Status creationTime="2010-07-06T17:19:13.501+02:00">
<ns3:ProcessAccepted>ProcessConfiguration has been accepted.</ns3:ProcessAccepted>
</ns3:Status>
<ns3:ProcessOutputs />
</ns3:ExecuteResponse>

Sorry this is the correct xml. I have received it from a jQuery Ajax call. Thanks.

michele
You can edit your question to add/change this, rather than posting it as an answer.
Crescent Fresh
A: 

Here is one way to do it:

var xml = null;
function loadXML(myURL){
    $.ajax({
        type: "GET",
        url: myURL,
        dataType: ($.browser.msie) ? "text" : "xml",
        error: function(){
            return;
        },
        success: function(data){
             if (typeof data == "string") {
               xml = new ActiveXObject("Microsoft.XMLDOM");
               xml.async = false;
               xml.loadXML(data);
                } else {
               xml = data;
             }
        }
    });
};
$(loadXML("common/glossary.xml"));

then

$(xml).find('something')
mkoryak
What's wrong with using `dataType:"xml"` in all browsers? What does IE have against xml?
Crescent Fresh
Crescent Fresh: Nothing.
Tim Down