I have a string containing a partial XML fragment, which may contain various undeclared namespaces and therefore cannot be parsed by the XML parser I'm using (.Net's XElement.Parse
):
<elements>
<removeThis:element attribute="value">
Contents
</removeThis:element>
</elements>
So before passing the string to the XML parser I need to strip the namespaces from the string (I don't need the namespaces, I just need the fragment to parse):
<elements>
<element attribute="value">
Contents
</element>
</elements>
Any suggestions on ways to achieve this result, e.g. a Regular Expression, or some option I'm not ware of within .Net's XML parser?