提取xml的节点值时出错.错误:需要命名空间管理器或XsltContext

我试图在xml中提取节点的值.由于其名称空间,我面临一些问题.在xml下面,我想要’faultstring’标签的值.

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
 <SOAP-ENV:Fault>
  <faultcode>Error</faultcode>
  <faultstring>Invalid combination of Username and Password.</faultstring>
  </SOAP-ENV:Fault>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我使用以下代码获取值.但它会引发错误.

Dim xmlDoc As New XmlDocument
    Dim namespaces As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.NaMetable)

    namespaces.AddNamespace("ns","SOAP-ENV")
    xmlDoc.Load("SOAP.xml")
    Dim oNode = xmlDoc.SelectSingleNode("ns:Envelope/ns:Body/ns:Fault/faultstring")
    MsgBox(oNode.InnerXml.ToString)

我没有得到任何解决方案.如果有人可以帮助这个!谢谢 !

解决方法

由于我对我的问题没有任何帮助,我试了试.解决方代码如下.

Dim xmlDoc As New XmlDocument
    Dim namespaces As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.NaMetable)

    namespaces.AddNamespace("SOAP-ENV","http://schemas.xmlsoap.org/soap/envelope/")
    xmlDoc.Load("SOAP.xml")

    Dim xPathString = "/SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/faultstring"
    Dim oNode = xmlDoc.SelectSingleNode(xPathString,namespaces)

它现在工作正常!!欢呼!!

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念