ikantspelwurdz
Well-known member
- Joined
- Dec 8, 2009
- Messages
- 49
- Programming Experience
- 1-3
Take this sample code:
The first two lines can not be changed. They reflect input coming from an outside system.
As is, this code will not work. The XML namespace is throwing this off.
What's the right way of handling this situation?
VB.NET:
Dim sXml As String = "<n1 xmlns=" & ControlChars.Quote & "n2" & ControlChars.Quote & "><n3>n4</n3></n1>"
Dim address As String = "n1/n3"
Dim xDoc As New XmlDocument
xDoc.LoadXml(sXml)
Dim xNsmgr As New XmlNamespaceManager(xDoc.NameTable)
xNsmgr.AddNamespace("n2", "n2")
Dim s As String = xDoc.SelectSingleNode(address, xNsmgr).InnerText
The first two lines can not be changed. They reflect input coming from an outside system.
As is, this code will not work. The XML namespace is throwing this off.
What's the right way of handling this situation?