如何读取xml文件 [英] How to read an xml file

查看:88
本文介绍了如何读取xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#.net,需要了解如何读取xml文件.我找到了一些参考,但是我仍然不确定c#确实具有执行我所需功能的功能.我的引用是 http://andrewsolymosi.sys-con.com/node/40761/mobile [ ^ ]

并且 C#.Net中的XML和XSLT简介 [ ^ ]

对于第一个参考,我认为它有一个使用字符串并将其放入xml类中以便稍后进行进一步处理的示例,但是我现在没有看到.我知道如何将文件读取为字符串,但是不知道如何将文件处理为可用的xml.

第二个参考文献似乎也不是我所需要的.我已经有了xml,并且不想将其一点一点地重新处理成节点,属性和元素.当然,必须有一个很好的方法来利用c#的功能轻松实现此目的.

有人有这样的例子吗?

谢谢!

解决方案

试试这个检查这个 [ ^ ]
并且以最简单的方式在C#中使用XML [ ^ ]


请查看我对XML解析的不同方法的简短概述:


  1. 使用System.Xml.XmlDocument类.它实现了DOM接口;如果文档太大,则这种方法最简单,也足够好.
    请参见
  2. 使用类System.Xml.XmlTextReader; library/system.xml.xmldocument.aspx"target =" _ blank"title =" New Window> ^ ].
  3. 使用类System.Xml.XmlTextReader;这是最快的读取方法,尤其是您需要跳过一些数据.
    请参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [http://msdn.microsoft.com/en-us/library/bb387063.aspx [ http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

    —SA


检查本文.我已经简要解释过了.还附有源代码.

XML到DataSet或GridView并返回 [ ^ ]

I''m using c# .net and need to find out how to read an xml file. I found a couple of references but I''m still not sure that c# actually has functions to do what I need. My references are http://andrewsolymosi.sys-con.com/node/40761/mobile[^]

And Introduction to XML and XSLT in C#.Net[^]

For the first reference, I thought it had an example of taking a string and putting it in an xml class for further processing later, but I''m not seeing that now. I know how to read the file into a string, but not how to process the file into usable xml.

The second reference doesn''t seem to be what I need either. I have xml already and didn''t want to re-process it bit by bit into nodes, attributes, and elements. Surely there must be a good way to do this easily with the functions of c#.

Does anyone have an example of this?

Thanks!

解决方案

Try this Check this[^]
And this Using XML in C# in the simplest way[^]


Please see my short overview of different methods of XML parsing:


  1. 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[^].
  2. 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[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, 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[^].



I''m not sure you really need working with XML directly. Chances are, you would rather need serialization, in particular, Data Contract. Please see:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

—SA


Check this article. I have explained briefly. Also source code is attached.

XML to DataSet or GridView and back[^]


这篇关于如何读取xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆