我需要使用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>
答案 0 :(得分:1)
如果要提取loginReturn,则可以采用以下方法:
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;