csharp中SAX解析期间的XML寻址 [英] XML addressing during SAX parsing in csharp

查看:134
本文介绍了csharp中SAX解析期间的XML寻址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在SAX解析期间获取XML文档中元素的地址,其中函数:StartElement和EndElement分别用于获取元素打开和关闭事件.

How to get the address of elements in XML document during the SAX parsing, where functions : StartElement, EndElement are used to get the elements opened and closed events respectively.

推荐答案

我不知道任何用于.NET的SAX解析器.它们不是真正需要的,也不包含在.NET Framework中.相反,在类System.Xml.XmlReader中实现了另一种只进技术:
http://msdn.microsoft.com/en-us/library/system.xml. xmlreader.aspx [ ^ ].

另请参阅有关SAX和XmlReader比较的这篇文章:
http://msdn.microsoft.com/en-us/library/sbw89de7.aspx [ ^ ].

如果确实需要,可以通过以下方式创建与SAX完全等效的技术:
I don''t know any SAX parsers for .NET. They are not really needed and not included in .NET Framework. Instead, there is a different forward-only technology implemented in the class System.Xml.XmlReader:
http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].

Please also see this article on SAX and XmlReader comparison:
http://msdn.microsoft.com/en-us/library/sbw89de7.aspx[^].

If you really want, you can create a technique fully equivalent to the SAX in the following way:
class SaxEventArgs : System.Args() {
    internal SaxEventArgs(
        System.Xml.XmlReader.NodeType,
        string localName,
        string namespace,
        //...
    );
    public System.Xml.XmlReader.NodeType NodeType { get; private set; }
    public string LocalName { get; private set; }
    //...
} //SaxEventArgs

//...

public event System.EventHandler<saxeventargs> XmlNodeParsed;

void InvokeSaxEvent(XmlReader reader) {
    if (XmlNodeParsed != null)
        XmlNodeParsed.Invoke(reader, new SaxEventArgs(reader.NodeType, reader.LocalName, /* ... */));
}

//...

while (reader.Read()) {
   InvokeSaxEvent(reader);
}</saxeventargs>



你有主意吗?

但是,我认为您永远不需要它. :-)
我认为XmlParser更好.您可以解析任何内容.如果您遇到问题,欢迎提出其他问题.

祝你好运,

—SA



Are you getting the idea?

However, I don''t think you will ever need it much. :-)
I think the XmlParser is better. You can parse whatever you want. If you face some problems, you are welcome to ask another question.

Good luck,

—SA


我不知道用于.NET的任何SAX解析器.它们不是真正需要的,也不包含在.NET Framework中.相反,在类System.Xml.XmlReader中实现了另一种只进技术:
http://msdn.microsoft.com/en-us/library/system.xml. xmlreader.aspx [ ^ ].

另请参阅有关SAX和XmlReader比较的这篇文章:
http://msdn.microsoft.com/en-us/library/sbw89de7.aspx [ ^ ].

如果确实需要,可以通过以下方式创建与SAX完全等效的技术:
I don''t know any SAX parsers for .NET. They are not really needed and not included in .NET Framework. Instead, there is a different forward-only technology implemented in the class System.Xml.XmlReader:
http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].

Please also see this article on SAX and XmlReader comparison:
http://msdn.microsoft.com/en-us/library/sbw89de7.aspx[^].

If you really want, you can create a technique fully equivalent to the SAX in the following way:
class SaxEventArgs : System.Args() {
    internal SaxEventArgs(
        System.Xml.XmlReader.NodeType,
        string localName,
        string namespace,
        //...
    );
    //...
} //SaxEventArgs

//...

System.EventHandler<saxeventargs> XmlNodeParsed;

void InvokeSaxEvent(XmlReader reader) {
    if (XmlNodeParsed != null)
        XmlNodeParsed.Invoke(reader, new SaxEventArgs(reader.NodeType, reader.LocalName, /* ... */));
}

//...

while (reader.Read()) {
   InvokeSaxEvent(reader);
}</saxeventargs>



你有主意吗?

但是,我认为您永远不需要它. :-)
我认为XmlParser更好.您可以解析任何内容.如果您遇到问题,欢迎提出其他问题.

祝你好运,

—SA



Are you getting the idea?

However, I don''t think you will ever need it much. :-)
I think the XmlParser is better. You can parse whatever you want. If you face some problems, you are welcome to ask another question.

Good luck,

—SA


这篇关于csharp中SAX解析期间的XML寻址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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