[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

problem using java.util.Stack with SAX

  • From: "Stockett, Jeff" <stockett@q...>
  • To: "'xml-dev@i...'" <xml-dev@i...>
  • Date: Sun, 2 May 1999 15:24:30 -0500

java.util.stack
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
Reporter?"/>
    <tocitem target="booktoca_htm_641021" text="Finding the Report You
Need"/>
    <tocitem target="booktoca_htm_641023" text="Using Help"/>
  </tocitem>
</toc>

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);
                
                Contents.append(child);
                
                stack.push(child);
              }
              else
              {
                symantec.itools.awt.TreeNode child = new
symantec.itools.awt.TreeNode(text, Contents);
                
                symantec.itools.awt.TreeNode parent =
(symantec.itools.awt.TreeNode) stack.peek();
                
                stack.push(child);
                
                Contents.addChild(child, parent);        
              }
            }
        } 

        public void endElement(String name)
        {
            System.out.println("End element: " + name);
            
            if (name.equals("toc"))
              Contents.redraw();
              
            if (name.equals("tocitem"))
              stack.pop();
        }
    }

Now I get a SAXException of type null when the first check to stack.empty()
happens?
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
methods
are declared synchronized?

Best Regards,


Jeff Stockett
Quadralay Corporation

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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.