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

解决方案 »

  1.   

    需要使用XmlNamespaceManager 
      

  2.   

    但我用的是XML SDK 中的  DOM。不是.NET类库中的那个。该怎么做? 还请明示。谢谢 !!
      

  3.   

    xmlDoc.setProperty"SelectionNamespaces",       "your xml namespace");
       xmlDoc.setProperty("SelectionLanguage", "XPath");
      

  4.   

    http://support.microsoft.com/kb/280457/zh-cn
      

  5.   

    <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);
    else
    alert("无");
     
    //-->
    </SCRIPT>
      

  6.   

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

  7.   

    多谢大家的帮助。道理我已经看懂了。可是得到的结点仍为null..我刚刚写的代码同上面幕白兄几乎是一模一样的。。XML文本格式同上面的也是完全一样的。我真是搞不懂为什么谢谢 !var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
    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;
      

  8.   

    多谢孟子。这回可以了。看来XML的东西我还要好好补补。。看来每一个节点都要指定名空间才行的。  。谢谢你们!!