Tag Archives: xpath

Remove namespaces from Xpath expression

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

/ElementOne/ElementTwo/ElementThree

Thanks Bogdan Emil Mariesan @ Stack Overflow for the solution