Bryan,
You are almost there... ;-) Inline.
Bryan said:
xTest.LoadXml(sData)
xNSM = New Xml.XmlNamespaceManager(xTest.NameTable)
xNSM.AddNamespace("SOAP-ENV", "
http://tempuri.org/SOAP-ENV")
Here is your first problem. When you add the namespace, it needs to
match the namespace declaration in the XML. It uses it is a lookup, so
if both parts don't match, it fails. Change this line in your code to:
xNSM.AddNamespace("SOAP-ENV",
"
http://schemas.xmlsoap.org/soap/envelope/")
xElem =
xTest.GetElementById("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber")
sVal = xElem.Value
The problem here is that you need to query within the context of the
XmlNamespaceManager. To do this, use SelectSingleNode(), like this:
Dim nodRetrieve As XmlNode
nodRetrieve =
xTest.SelectSingleNode("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber",
xNSM)
But I'm still getting the error: "Object reference not set to an instance of
an object." on the last line of code that I included here. I'm still not
getting anything returned from the GetElementById function.
What now?
So, I made a quick and dirty sample using the snippet of the XML that
you made along with a modified version of the source you posted. Mine
looks like this:
Dim xTest As New XmlDocument
Dim sData As String = _
"<SOAP-ENV:Envelope
xmlns:SOAP-ENV=""
http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<SOAP-ENV:Body>" & _
"<PurchaseOrder>" & _
"<OrderHeader> " & _
"<BuyerOrderNumber>TestPo1</BuyerOrderNumber> " & _
"</OrderHeader> " & _
"</PurchaseOrder>" & _
"</SOAP-ENV:Body>" & _
"</SOAP-ENV:Envelope>"
Dim xNSM As System.Xml.XmlNamespaceManager
Dim xElem As XmlElement
Dim sVal As String
xTest.LoadXml(sData)
xNSM = New Xml.XmlNamespaceManager(xTest.NameTable)
xNSM.AddNamespace("SOAP-ENV",
"
http://schemas.xmlsoap.org/soap/envelope/")
Dim nodRetrieve As XmlNode
nodRetrieve =
xTest.SelectSingleNode("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber",
xNSM)
sVal = nodRetrieve.InnerText
Let me know if that gets it working for you!
Joseph