【问题标题】:Remove xmlns attribute with namespace prefix删除带有命名空间前缀的 xmlns 属性
【发布时间】:2012-11-28 21:49:30
【问题描述】:

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

如何从XElement 中删除xmlns:xx 属性?

【问题讨论】:

    标签: c# xml vb.net xelement


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-04
      • 1970-01-01
      • 2019-04-10
      • 1970-01-01
      相关资源
      最近更新 更多