About Nikos Maravitsas

Nikos has graduated from the Department of Informatics and Telecommunications of The National and Kapodistrian University of Athens. During his studies he discovered his interests about software development and he has successfully completed numerous assignments in a variety of fields. Currently, his main interests are system’s security, parallel systems, artificial intelligence, operating systems, system programming, telecommunications, web applications, human – machine interaction and mobile development.

Read XML File in Java using SAX parser example

In this tutorial we are going to see how you can parse an XML File using a SAX parser. SAX parsers are very popular and much more frequently used than DOM parsers. The reason is that they are much more memory efficient (and this is important for large XML Files) and much faster. It’s all down to the way the SAX parsers work. They don’t create an object with tree structure and store it in the memory while parsing the file. The idea of the SAX parsing is much simpler and it lies in callback methods. Basically there are 3 groups of callback methods:

startDocument() and endDocument(), called at the start and end of an XML document.

startElement() and endElement() called at the start and end of an element tag.

characters() called when the text contents between the start and end tags of an elements are parsed.

These are the functions that inform the clients about the structure of the XML File. In order to implement these functions you have to create a class that extends org.xml.sax.helpers.DefaultHandler class as you can see in the code snippets that follow.

4. Java Annotations Tutorial3>

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

and many more ....

Newsletter

Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

Email address:

Join Us

With 1,043,221 monthly unique visitors and over 500 authors we are placed among the top Java related sites around. Constantly being on the lookout for partners; we encourage you to join us. So If you have a blog with unique and interesting content then you should check out our JCG partners program. You can also be a guest writer for Java Code Geeks and hone your writing skills!

Disclaimer

All trademarks and registered trademarks appearing on Examples Java Code Geeks are the property of their respective owners. Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. Examples Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.