如何在C#中使用事件驱动的SAX(XML的简单API)解析器,还是最好使用System.XML命名空间? [英] How to use the event driven SAX(Simple API FOR XML) parser in C# or is it better to use System.XML namespace?

查看:66
本文介绍了如何在C#中使用事件驱动的SAX(XML的简单API)解析器,还是最好使用System.XML命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,我们可以将msxml DLL导入我们的应用程序,然后在我们的应用程序的类中实现ISAXContentHandler接口的方法.稍后创建一个ISAXReader对象,并使用该类的实例调用contentHandler,在该实例中,我们已为事件处理程序接口提供了实现.
同样,我想在C#中实现相同的目的.有什么办法可以在C#中做到这一点吗?我的意思是有什么办法可以在C#中进行基于事件的SAX解析.我认为还有另一种方法可以帮助我解析XML文档并将XML信息获取到我的应用程序中.我点击了链接" http://www.codeguru.com/csharp/csharp/cs_data/xml/article.php/c4221 "

In C++ we can import msxml DLL to our application and then implement the methods of the interface ISAXContentHandler in a class of our application. Later create an ISAXReader object and invoke the contentHandler with the instance of this class where we have given the implemnatation for the eventhandler interfaces.
Similiarly I want to achieve the same thing in C#. Is there any way to do this in C#?? I mean is there any way to have eventbased SAX parsing in C#. There is one more method I thought would help me in achieving parsing the XML documant and getting the XML information to my application. I followed the link "http://www.codeguru.com/csharp/csharp/cs_data/xml/article.php/c4221"

在此使用DOM,并在使用System.XML命名空间.任何人都可以在这方面帮助我,---- 用C#实现事件驱动的XML解析的方法是什么或者我应该使用System.XML命名空间(DOM).如果存在SAX事件驱动方式,请让我知道如何使用C#

Here DOM is used and System.XML namespace is being used. Can anyone kindly help me with this regard,----What is the way to achieve Event driven XML parsing in C# or should I use System.XML namespace (DOM). if there exists a SAX event driven way plz let me know how to do it in C#

推荐答案

我认为您最接近.Net框架中的SAX阅读器的地方是 XmlReader 类.它不是基于事件的,但是它允许您以类似的方式遍历文档.请看以下示例: http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.read.aspx

I think the closest you get to a SAX-reader in the .Net framework is the XmlReader class. It is not event based, but it allows you to iterate through the document in a similar manner. Look at this example: http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.read.aspx

如果您需要最大的性能,那么XmlReader是一个不错的选择,但是还有其他替代方法可以提供更友好的api.通过 XmlDocument 类,您可以将xml文档视为分层树,而 XDocument 允许您使用LINQ解析xml.您需要哪种型号取决于您喜欢哪种型号以及您的要求.

If you need maximum performance then the XmlReader is a good choice, but there are other alternatives that offer a more friendly api. The XmlDocument class allows you to treat the xml document as a hierarchical tree, while the XDocument allows you to use LINQ to parse the xml. Which one you need depends on which model you are comfortable with and your requirements.

这篇关于如何在C#中使用事件驱动的SAX(XML的简单API)解析器,还是最好使用System.XML命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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