Remove namespaces from Xpath expression

By , March 20, 2012 11:12 am

If you ever need to remove namespaces from an XPath string, regex is a way to go. [\w]+:(?!:) expression to be precise. So if, for example your xpath is

Dim sXpath as String = "/ns1:ElementOne/ElementTwo/ns2:ElementThree"

this code

Regex.Replace(sXpath, "[\w]+:(?!:)", "")

will convert it into


Thanks Bogdan Emil Mariesan @ Stack Overflow for the solution

Leave a Reply

Panorama Theme by Themocracy