从c#windows窗体应用程序中的xml文件逐行读取数据 [英] Read data line by line from xml file in c# windows form application
本文介绍了从c#windows窗体应用程序中的xml文件逐行读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个xmal文件
< bookstore>
< book category =Children>
< bookname> ;
< author>
< price>
< book category =Web>< ; br mode =hold =/>< Bookname =web =disegn =>< br mode =harry =bruk =>< br mode =40 => ;< br mode =>
I am creating a xmal file
<bookstore>
<book category="Children">
<bookname>
<author>
<price>
<book category="Web><br mode=" hold=" /> <Bookname =" web="" disegn="><br mode=" harry="" bruk="><br mode=" 40="><br mode=">
推荐答案
逐行读取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接口;如果文档的大小不是太大,这种方式是最简单和最好的。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ ^ ]。 - 使用类
System.Xml.XmlTextReader
;这是最快的阅读方式,特别是你需要跳过一些数据。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ ^ ]。 - 使用类
System.Xml.Linq.XDocument
;这是类似于XmlDocument
的最合适的方式,支持LINQ to XML Programming。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ ^ ],http://msdn.microsoft.com/en-us/library/bb387063.aspx [ ^ ]。
- Use
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.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the class
System.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that ofXmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
祝你好运,
这篇关于从c#windows窗体应用程序中的xml文件逐行读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文