C# XML 去xmlns:xsd和xmlns:xsi属性
2024-08-31 20:46:09
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();
最新文章
- JavaScript操作Cookie
- 【hive】——Hive基本操作
- .NET 4.5+项目迁移.NET Core的问题记录
- (37) 在命令行调用API
- 转:switch内部的变量定义问题(goto类似)
- C语言字符串声明
- POJ 1236 Network of Schools (有向图的强连通分量)
- POJ1502: MPI Maelstrom
- (转)PHP中extract()函数的妙用
- JavaScript中的Array对象
- asp.net事件委托易理解实例
- 使用gson(一)
- 【android错误】bitmap size exceeds 32bits
- CSS 背景 background 讲解
- Python+requests库 POST接口图片上传
- Genymotion下载慢或者下载失败的解决办法
- Redis初步整理
- fedora输入法
- QL Server 高可用性(一)AlwaysOn 技术
- github上删除一个项目或者reposity