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);
------解决方案--------------------------------------------------------
需要使用XmlNamespaceManager
------解决方案--------------------------------------------------------
xmlDoc.setProperty "SelectionNamespaces ", "your xml namespace ");
xmlDoc.setProperty( "SelectionLanguage ", "XPath ");
------解决方案--------------------------------------------------------
http://support.microsoft.com/kb/280457/zh-cn
------解决方案--------------------------------------------------------
<SCRIPT language= "javascript "> <!-- 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);elsealert( "无 "); //--> </SCRIPT>
------解决方案--------------------------------------------------------
<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 ' ")