Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XML read
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 17-Jul-12 0:09am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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>
 
Are you getting the idea?
 
However, I don't think you will ever need it much. Smile | :)
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
  Permalink  
v3
Comments
Rasha8876 at 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 at 27-Jul-12 19:36pm
   
Pointers, in .NET? You probably mean something else. What?
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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>
 
Are you getting the idea?
 
However, I don't think you will ever need it much. Smile | :)
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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 495
1 Maciej Los 340
2 Richard MacCutchan 265
3 BillWoodruff 225
4 Mathew Soji 200
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 27 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100