Remove xmlns attribute with namespace prefix

This question is a logical continuation of this - now suppose the XElement contains elements in a namespace other than the default:

 <Body xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"> <ReportItems /> <Height /> <rd:Style /> </Body> 

I am trying to use the same approach as in the answer to my previous question, i.e. remove the xmlns attribute, but it does not work when it is prefixed with xmlns +, like this xmlns:xx .

TL DR version

It works:

 Dim xml = <Body xmlns="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"/> xml.Attribute("xmlns").Remove() 

It does not mean:

 Dim xml = <Body xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"/> xml.Attribute("xmlns:rd").Remove() 

Getting this error:

 XmlException was unhandled The ':' character, hexadecimal value 0x3A, cannot be included in a name. 

How to remove xmlns:xx attribute from XElement ?

+4
source share
1 answer

Try this instead:

 xml.Attribute(XNamespace.Get("http://www.w3.org/2000/xmlns/") + "rd").Remove() 
+4
source

All Articles