在.NET操作XML的最佳方式操作、方式、NET、XML

由网友(超负荷)分享简介:我需要处理现有的XML文档,并从它创建一个新的,删除一些节点和属性,并可能增加新的,什么是班级最好的小组做到这一点?I need to manipulate an existing XML document, and create a new one from it, removing a few nodes and...

我需要处理现有的XML文档,并从它创建一个新的,删除一些节点和属性,并可能增加新的,什么是班级最好的小组做到这一点?

I need to manipulate an existing XML document, and create a new one from it, removing a few nodes and attributes, and perhaps adding new ones, what would be the best group of classes to accomplish this?

有很多.NET类的XML处理的,我不知道会是这样做的最佳方法。

There are a lot of .NET classes for XML manipulation, and I'm not sure what would be the optimal way to do it.

推荐答案

如果它确实是一个巨大的XML无法装入内存,你应该使用的的XmlReader /的的XmlWriter 。如果没有 LINQ到XML 是很容易使用。如果没有.NET 3.5,你可以使用的XmlDocument

If it is a really huge XML which cannot fit into memory you should use XmlReader/XmlWriter. If not LINQ to XML is very easy to use. If you don't have .NET 3.5 you could use XmlDocument.

下面是删除节点的例子:

Here's an example of removing a node:

using System.Xml.Linq;
using System.Xml.XPath;

var doc = XElement.Load("test.xml");
doc.XPathSelectElement("//customer").Remove();
doc.Save("test.xml");
阅读全文

相关推荐

最新文章