Error in extracting node xml value. Error: Name Manager or XsltContext Required

I am trying to extract the node value in xml. I am facing some problems due to its namespace. In the below xml, I want the value of the tag "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> 

I use the following code to get the value. But it causes an error.

 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) 

I do not get any solution. If anyone can help with this! Thanks!

+4
source share
1 answer

Since I did not receive any help on my question, I tried myself. The solution code is as follows.

  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) 

Now it works great! greetings!

+3
source

Source: https://habr.com/ru/post/1395170/


All Articles