4

这个问题是这个问题的逻辑延续-现在假设一个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

4

1 回答 1

4

试试这个:

xml.Attribute(XNamespace.Get("http://www.w3.org/2000/xmlns/") + "rd").Remove()
于 2012-11-28T22:08:50.303 回答