如何拆分xml文件 [英] How to split xml files
本文介绍了如何拆分xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要拆分拥有1000个节点的xml文件,但这些节点中有命名空间(常用命名空间),我想删除它在分割时遇到麻烦的命名空间,拆分后我想添加分隔文件。
是否有任何方法可以分配名称空间请帮助
Hi ,I need to split xml files which is having 1000 nodes,but these nodes have namespace( common namespaces ) in it I want to remove the namespaces its making trouble in splitting ,after splitting i want to add in separated files .
Is there any way to split with having namespaces please help
推荐答案
根据您引用的文章:使用LINQ分割大型XML文件的简便方法到XML [ ^ ] ...
所有你需要做的就是调用RemoveAllNamespaces
函数将c1
变量传入其中:
Based on the article you referenced: Easy Method to Split Large XML File Using LINQ to XML[^]...
All you need to do is to callRemoveAllNamespaces
function passingc1
variable into it:
private static XElement RemoveAllNamespaces(XElement xmlDocument)
{
if (!xmlDocument.HasElements)
{
XElement xElement = new XElement(xmlDocument.Name.LocalName);
xElement.Value = xmlDocument.Value;
foreach (XAttribute attribute in xmlDocument.Attributes())
xElement.Add(attribute);
return xElement;
}
return new XElement(xmlDocument.Name.LocalName, xmlDocument.Elements().Select(el => RemoveAllNamespaces(el)));
}
以上功能来自: http://stackoverflow.com/questions/987135/how-to-remove-all-namespaces-from-xml-with -c [ ^ ]
我会这样称呼:
Above function comes from: http://stackoverflow.com/questions/987135/how-to-remove-all-namespaces-from-xml-with-c[^]
I'd call it this way:
XElement frag = new XElement(rootElement, RemoveAllNamespcaes(c1));
这篇关于如何拆分xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文