2010-07-07 3 views
0

Jquery를 사용하고 있습니다. webservice에서 xml이 반환되었습니다. 그래서 나는 그것으로부터 약간의 가치를 추출하고 싶다. Jquery가 요청에서 XML을 파싱합니다.

는 XML 예제는 웹 서비스에서 반환됩니다

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

그래서 내 코드는 다음과 같습니다

내가 NS3의 statusLocation 속성을 추출 할 수있는 방법
$.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); 
    } 
}); 

: ExecuteResponse 노드를?

고마워요.

+0

가능한 중복 컨트롤을 사용하여/3187819/jquery-parsing-xml) –

+1

이미 질문을 받았으며 정답을 받았습니다. 여러분에게 지적한 것처럼 XML을 파싱 할 필요가 없다. dataType으로''xml ''을 사용하면'success' 콜백에 XML 문서를 받게 될 것이다. –

+0

xml을 직접 파싱한다고해도 어쨌든 다른 질문에 답이 주어집니다 :'xmlDoc.documentElement.getAttribute ("statusLocation")'. –

답변

1

당신은 너무 간단하게 그

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

보다는 그것을 할 수없는 액티브 X는 [\ [jQuery를 \] XML 파싱 (http://stackoverflow.com/questions의

관련 문제