Use SelectSingleNode with Namespace in .NET

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

<myDoc xmlns="urn:blabla">
  <tag>text</tag>
</myDoc>

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?

/Martin
Comment
Watch Question

Do more with

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

      Dim doc as XmlDocument = new XmlDocument()
      doc.Load("booksort.xml")

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

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

mnp

Author

Commented:
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