我试图在xml中提取节点的值.由于其名称空间,我面临一些问题.在xml下面,我想要’faultstring’标签的值. SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"SOAP-ENV:Body SOAP-ENV:Fault f
<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)
它现在工作正常!!欢呼!!