Use SelectSingleNode with Namespace in .NET

mnp used Ask the Experts™
Previously, when I had a namespace declaration in my XML document like this:

<myDoc xmlns="urn:blabla">

I could use setProperty with SelectionNamespaces to be able to use selectSingleNode. (MSXML4.0)

Now I would like to do the same thing using the .NET Framework. I have managed to do this by using an XPathNavigator and XmlNamespaceManager, but my question is if there is any, in my opinion, easier way like before?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

      Dim doc as XmlDocument = new XmlDocument()

      Dim nsmgr as XmlNamespaceManager = new XmlNamespaceManager(doc.NameTable)
      nsmgr.AddNamespace("b", "urn:blabla")

      Dim book as XmlNode = doc.SelectSingleNode("//b:myDoc", nsmgr)



Very easy and straightforward. Thanks a lot!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial