public static XElement WithoutNamespaces(this XElement element)
{
if (element == null) return null; #region delegates: Func<XNode, XNode> getChildNode = e => (e.NodeType == XmlNodeType.Element) ? (e as XElement).WithoutNamespaces() : e; Func<XElement, IEnumerable<XAttribute>> getAttributes = e => (e.HasAttributes) ?
e.Attributes()
.Where(a => !a.IsNamespaceDeclaration)
.Select(a => new XAttribute(a.Name.LocalName, a.Value))
:
Enumerable.Empty<XAttribute>(); #endregion return new XElement(element.Name.LocalName,
element.Nodes().Select(getChildNode),
getAttributes(element));
}

  调用

 var xDoc = XDocument.Parse(xml);
var xRoot = xDoc.Root.WithoutNamespaces();

  

最新文章

  1. JavaScript操作Cookie
  2. 【hive】——Hive基本操作
  3. .NET 4.5+项目迁移.NET Core的问题记录
  4. (37) 在命令行调用API
  5. 转:switch内部的变量定义问题(goto类似)
  6. C语言字符串声明
  7. POJ 1236 Network of Schools (有向图的强连通分量)
  8. POJ1502: MPI Maelstrom
  9. (转)PHP中extract()函数的妙用
  10. JavaScript中的Array对象
  11. asp.net事件委托易理解实例
  12. 使用gson(一)
  13. 【android错误】bitmap size exceeds 32bits
  14. CSS 背景 background 讲解
  15. Python+requests库 POST接口图片上传
  16. Genymotion下载慢或者下载失败的解决办法
  17. Redis初步整理
  18. fedora输入法
  19. QL Server 高可用性(一)AlwaysOn 技术
  20. github上删除一个项目或者reposity

热门文章

  1. android studio 2.2 使用cmake编译NDK
  2. idea中建立一个OSGI项目
  3. 5.3.3.1 deque其他使用方式
  4. Qt for WebAssembly
  5. 并发编程--CAS自旋锁
  6. WPF Opacity 最小值多少会被击穿
  7. 更改MyEclipse编辑框的背景颜色
  8. Windows完成端口与Linux epoll技术简介(能看懂)
  9. 微信小程序实例:实现tabs选项卡效果
  10. js 图片缩显