使用JQuery从SOAP XML Response中提取

时间:2015-07-06 16:12:46

标签: jquery

我需要使用jQuery

从此XML响应中提取此值
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:loginResponse>
<loginReturn xsi:type="xsd:string">1cfc56c2007dec7b32cf20f0d44c2eeb</loginReturn>
</ns1:loginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

1 个答案:

答案 0 :(得分:1)

如果要提取loginReturn,则可以采用以下方法:

&#13;
&#13;
var xmlData = '<?xml version="1.0" encoding="UTF-8"?>'+
'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento"'+ 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'+ 
'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'+
'<SOAP-ENV:Body>'+
'<ns1:loginResponse>'+
'<loginReturn xsi:type="xsd:string">1cfc56c2007dec7b32cf20f0d44c2eeb</loginReturn>'+
'</ns1:loginResponse>'+
'</SOAP-ENV:Body>'+
'</SOAP-ENV:Envelope>';


var parsedData = $.parseXML(xmlData);
$('#resultlbl').text($(parsedData).find( "loginReturn").text())
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<label id='resultlbl'/>
&#13;
&#13;
&#13;