XML文件内容是这样的
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body><RegisterPersonMemberResponse xmlns="http://www.fztnet.com.cn/RegisterService">
<RegisterPersonMemberResult><IsSuccessful>true</IsSuccessful><Status>0</Status>
</RegisterPersonMemberResult></RegisterPersonMemberResponse>
</soap:Body></soap:Envelope>我使用这个XPATH表达式来求Status的值。/Envelope/Body/RegisterPersonMemberResponse/RegisterPersonMemberResult/Status但会出错。得到的空结点。
不知为什么。。谢谢 xmlDoc.setProperty("SelectionLanguage", "XPath");
var path = "/Envelope/Body/RegisterPersonMemberResponse/RegisterPersonMemberResult/Status";
var node = xmlDoc.selectSingleNode(path);
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body><RegisterPersonMemberResponse xmlns="http://www.fztnet.com.cn/RegisterService">
<RegisterPersonMemberResult><IsSuccessful>true</IsSuccessful><Status>0</Status>
</RegisterPersonMemberResult></RegisterPersonMemberResponse>
</soap:Body></soap:Envelope>我使用这个XPATH表达式来求Status的值。/Envelope/Body/RegisterPersonMemberResponse/RegisterPersonMemberResult/Status但会出错。得到的空结点。
不知为什么。。谢谢 xmlDoc.setProperty("SelectionLanguage", "XPath");
var path = "/Envelope/Body/RegisterPersonMemberResponse/RegisterPersonMemberResult/Status";
var node = xmlDoc.selectSingleNode(path);
xmlDoc.setProperty("SelectionLanguage", "XPath");
<!--
var str = "<?xml version=\"1.0\"?>"+
"<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"+
"<soap:Body><RegisterPersonMemberResponse xmlns=\"http://www.fztnet.com.cn/RegisterService\">"+
"<RegisterPersonMemberResult><IsSuccessful>true</IsSuccessful><Status>0</Status>"+
"</RegisterPersonMemberResult></RegisterPersonMemberResponse>"+
"</soap:Body></soap:Envelope>";
var dom = new ActiveXObject("MSXML2.DomDocument");dom.loadXML(str);
var path = "/soap:Envelope/soap:Body/RegisterPersonMemberResponse/RegisterPersonMemberResult/Status";
dom.setProperty("SelectionNamespaces","xmlns:soap='http://www.w3.org/2003/05/soap-envelope'");
var node = dom.selectSingleNode(path);if(node != null)
alert(node.text);
else
alert("无");
//-->
</SCRIPT>
var xmldom = new ActiveXObject("Msxml2.DOMDocument")
xmldom.loadXML("<?xml version='1.0'?><soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><RegisterPersonMemberResponse xmlns='http://www.fztnet.com.cn/RegisterService'><RegisterPersonMemberResult><IsSuccessful>true</IsSuccessful><Status>0</Status></RegisterPersonMemberResult></RegisterPersonMemberResponse></soap:Body></soap:Envelope>")xmldom.setProperty("SelectionLanguage","XPath")
xmldom.setProperty("SelectionNamespaces", "xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:a='http://www.fztnet.com.cn/RegisterService'")var path = "/soap:Envelope/soap:Body/a:RegisterPersonMemberResponse/a:RegisterPersonMemberResult/a:Status";
var node = xmldom.selectSingleNode(path);
alert(node.text)
</script>
alert(xmlhttp.responseXML.xml);
xmlDoc.loadXML(xmlhttp.responseXML.xml);
xmlDoc.setProperty("SelectionLanguage", "XPath");
xmlDoc.setProperty("SelectionNamespaces", 'xmlns:soap="http://www.w3.org/2003/05/soap-envelope"');
var path = "/soap:Envelope/soap:Body/RegisterPersonMemberResponse/RegisterPersonMemberResult/Status";
var node = xmlDoc.selectSingleNode(path);
var status = node.nodeValue;