这个问题是这个问题的逻辑延续-现在假设一个XElement
包含非默认命名空间中的元素:
<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>
我正在尝试采用与上一个问题的答案中建议的方法相同的方法,即删除xmlns
属性,但是当它是 xmlns + 前缀时它不起作用,就像这样xmlns:xx
。
TL;DR 版本
这有效:
Dim xml = <Body xmlns="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"/>
xml.Attribute("xmlns").Remove()
这不会:
Dim xml = <Body xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"/>
xml.Attribute("xmlns:rd").Remove()
收到此错误:
XmlException was unhandled
The ':' character, hexadecimal value 0x3A, cannot be included in a name.
如何xmlns:xx
从 中删除属性XElement
?