Groups | Blog | Home
all groups > dotnet xml > october 2005 >

dotnet xml : XPath with prefix and local name


Tom_B
10/5/2005 10:59:04 AM
The following returns a system error of System.Xml.XPath.XPathException.

Dim Nodes As XmlNodeList
Nodes = doc.SelectNodes("soap:Body")

How is the XPath string formed where there is a prefix and a local name for
the node?

Tom_B
10/5/2005 12:27:03 PM
Martin Honnen
10/5/2005 8:55:01 PM


[quoted text, click to view]

You need to use an XmlNamespaceManager, bind that prefix to a namespace
URI and pass the namespace manager as the second argument to SelectNodes.
VB pseudo code
Dim NamespaceManager as System.Xml.XmlNamespaceManager
NamespaceManager = New System.Xml.XmlNamespaceManager(doc.NameTable)
NamespaceManager.AddNamespace("soap", "putURIHere")
doc.SelectNodes("soap:Body", NamespaceManager)
Which URI you need depends on the input XML of course.

--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button