Recent Posts

Sunday, January 23, 2011

How to remove xmlns namespace from xml using

I was having issues with xmlns in xml file and was creating unnecessary waste of time handling them. But i found below solution to remove xmlns from the xml file so that I can focus on only the required tags.

Function stripDocumentNamespace(oldDom As XmlDocument) As XmlDocument
' Remove all xmlns:* instances from the passed XmlDocument
' to simplify our xpath expressions.
Dim newDom As New XmlDocument()
newDom.LoadXml(System.Text.RegularExpressions.Regex.Replace(oldDom.OuterXml, "(xmlns:?[^=]*=[""][^""]*[""])", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase Or System.Text.RegularExpressions.RegexOptions.Multiline))
Return newDom
End Function

Read more!