更新时间:2023-10-21 17:08:28
逐行读取XML数据将完全违背XML的目的。 XML文本并不是真正面向行的。你应该更好地使用.NET FCL上提供的XML解析器,而不是自己动手(为什么?)。这是我对它们的简短回顾:
Reading data from XML line by line would totally defeat the purpose of XML. And XML text is not really line-oriented. Instead of doing it by yourself (why?) you should better use on of XML parsers available on .NET FCL. This is my short review of them:
System.Xml.XmlDocument
class。它实现了DOM接口;如果文档的大小不是太大,这种方式是最简单和***的。 System.Xml.XmlTextReader
;这是最快的阅读方式,特别是你需要跳过一些数据。 System.Xml.Linq.XDocument
;这是类似于 XmlDocument
的最合适的方式,支持LINQ to XML Programming。System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.System.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.System.Xml.Linq.XDocument
; this is the most adequate way similar to that of XmlDocument
, supporting LINQ to XML Programming.
祝你好运,