Remove namespaces from Xpath expression

I need a way to remove namespaces from an XPath expression, for example if it goes something like this:



he should become



Namespaces can be different in XPath (ns1, ns2 in the above example) and can be applied at the beginning of the Xpath, for example



Regex? Any ideas?



source to share

2 answers

The regex matches the namespace format:




For the ancestor part, you can use the updated regex:



So the final solution is doing this: it looks for the previously declared structure with the entire alphanumeric + underscore character, followed by the ':' character, not followed by the second: character. Hope this helps.



Don't know the format of the xpath names, but the xml spec seems fuzzy to me about using colons as a namespace separator and a valid name character that should be accepted by processors. Although colons should only be used as a namespace separator.

So minus the confirmation of the unicode encoding is

To match the last colon:


To match the first colon:




All Articles