使用 C#/.NET 读/写 XML [英] Read/write XML with C#/.NET
本文介绍了使用 C#/.NET 读/写 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 C#/.NET 读/写 XML 的最佳功能、实践和/或技术是什么?
What are the best functions, practices, and/or techniques to read/write XML with C#/.NET?
推荐答案
有读取 XML 的类:
There are classes to read XML:
XmlDocument
速度慢且占用大量内存:它解析 XML 并将其加载到内存中的 DOM 中,如果您想编辑它,这很好.XmlReader
占用内存较少:它从前到后扫描 XML,无需一次将所有内容保存在 RAM 中.
XmlDocument
is slow and memory-intensive: it parses the XML and loads it into an in-RAM DOM, which is good if you want to edit it.XmlReader
is less memory-intensive: it scans the XML from front to back, never needing to keep all of it in RAM at once.
同样,为了编写,您可以构造一个 XmlDocument
然后保存它,或者使用 XmlWriter
.
Similarly, for writing you can construct an XmlDocument
and then save it, or use an XmlWriter
.
在我写完上述内容之后,现在有了一组更易于使用的新 API:例如 XDocument
和 XElement
类.
After I wrote the above, there's now a new set of APIs which are easier to use: i.e. for example the XDocument
and XElement
classes.
这篇关于使用 C#/.NET 读/写 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文