problem using java.util.Stack with SAX

Stockett, Jeff stockett at
Sun May 2 22:26:05 BST 1999

Hello.  I'm relatively new to Java, so please forgive if this is a simple
question.  I'm using SAX to render a treeview table of contens from 
XML where the source content looks something like:

<?xml version='1.0' encoding='ISO-8859-1' ?>
<toc version="1.0">
  <tocitem target="booktoca_htm_641017" text="Introduction">
    <tocitem target="booktoca_htm_641019" text="What is Transmitter
    <tocitem target="booktoca_htm_641021" text="Finding the Report You
    <tocitem target="booktoca_htm_641023" text="Using Help"/>

To handle tracking what level in the tree I'm at, I thought I'd use a stack
so my
handler is as follows:

    public class TOCHandler extends HandlerBase 
        private java.util.Stack stack;
        public void startElement(String name, AttributeList atts)
            System.out.println("Start element: " + name);
            if (name.equals("tocitem"))
              String text = atts.getValue("text");
              if (stack.empty())
                symantec.itools.awt.TreeNode child = new
symantec.itools.awt.TreeNode(text, Contents);
                symantec.itools.awt.TreeNode child = new
symantec.itools.awt.TreeNode(text, Contents);
                symantec.itools.awt.TreeNode parent =
(symantec.itools.awt.TreeNode) stack.peek();
                Contents.addChild(child, parent);        

        public void endElement(String name)
            System.out.println("End element: " + name);
            if (name.equals("toc"))
            if (name.equals("tocitem"))

Now I get a SAXException of type null when the first check to stack.empty()
What gives?  This was all working fine before I added the stack, but I fail
to see what
I'm doing wrong.  Does it have something to do with the fact that the stack
are declared synchronized?

Best Regards,

Jeff Stockett
Quadralay Corporation

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at
Archived as: and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo at the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at

More information about the Xml-dev mailing list