Home Ask Login Register

Developers Planet

Your answer is one click away!

user4591082 February 2016

SAX Parser not displaying full XML

I am having trouble with the SAX Parser where it is not retrieving the full xml document. I can see that it originates from the list as only 1 entry is added to the list when there should really be 3 entries.

Can anyone solve the issue by allowing all three entries to be display? Thank You.


<?xml version="1.0" ?>

    <TITLE>A Certain Justice</TITLE>
    <AUTHOR>P.D. James</AUTHOR>


    <TITLE>Ashworth Hall</TITLE>
    <AUTHOR>Anne Perry</AUTHOR>


    <TITLE>L.A. Confidential</TITLE>
    <AUTHOR>James Ellroy</AUTHOR>


    <TITLE>Shadow Woman</TITLE>
    <AUTHOR>Thomas Perry</AUTHOR>




package londonmet.cs.xml;

public class Catalogue {

  public String title;
  public String author;
  public String yearPublished;
  public String isbn;

  public String getTitle() {
    return title;
  public void setTitle(String title) {
    this.title = title;
  public String ge        


wero February 2016

You want to collect information about every BOOK element in your XML document.

Therefore in startElement and endElement you should watch for the start and end of BOOK and not CATALOG elements:

public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
    // reset
    tempVal = "";
    if (qName.equalsIgnoreCase("BOOK")) // not CATALOG

public void endElement(String uri, String localName, String qName) throws SAXException
    if (qName.equalsIgnoreCase("BOOK"))  // not CATALOG
        // add it to the list

Consequently you should rename your Catalogue class to Book class since it represents a single book and not a catalogue (= collection of books).

Post Status

Asked in February 2016
Viewed 1,950 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life

Devs Planet ®

2014-2016 www.devsplanet.com

Devs Planet © all rights reserved