Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

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:
C#
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>


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
 
Share this answer
 
v3
Comments
Rasha8876 17-Jul-12 14:20pm    
Thank you for reply, I used SAX.net2.1 version which is built for csharp,
I want to get the address of XML elements to be used in successive processing,
How to get such pointers to elements within the XML document.
Sergey Alexandrovich Kryukov 27-Jul-12 19:36pm    
Pointers, in .NET? You probably mean something else. What?
--SA
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:
C#
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>


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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900