Wesley Marshall Wesley Marshall - 1 year ago 61
Vb.net Question

How to get the default namespace when parsing an XML document?

I am trying to parse an XML file (using VB.Net) and get the default namespace of the root element to add to a XMLNamespaceManager that will be applied to a different XML object.

I have tried several methods, but none have worked. The code snippet below is my most recent attempt:

Dim rdlXml As System.Xml.XmlDocument = New System.Xml.XmlDocument()
rdlXml.Load(reportDir & "/" & report & ".rdl")

Dim root As XmlNode = rdlXml.DocumentElement

Dim nsMgr as System.Xml.XmlNamespaceManager = new System.Xml.XmlNamespaceManager(rdlXml.NameTable)

This code does not seem to successfully add the namespace to nsMgr.

What am I missing here?

EDIT: I am using .NET 2.0

Answer Source

Use: nsMgr.AddNamespace(String.Empty, root.NamespaceURI)