Recent Posts

Sunday, January 23, 2011

How to remove xmlns namespace from xml using vb.net

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.

Private
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

Related Posts by Categories




3 comments:

Anonymous said...

very nice, Thanks..

Walter Nuñez said...

i get "Error Xml Root Elemet Is missing"

Walter Nuñez said...

apparently is also necessary to eliminate the prefixes

Post a Comment