title: Java SAX Parser, storing Attributes
body: <p>I'm trying to store the current document position in a stack, pushing on startElement, popping on endElement. Right now I'm using:</p>
  
  <pre><code>public void startElement(String namespaceURI, String elname,
                           String qName, Attributes atts) throws SAXException {
      original.append(innerText);
      original.append("&lt;");
      original.append(elname);
      original.append("&gt;");
      docStack.push(new StackElement(elname,atts));
  ....
  </code></pre>
  
  <p>Unfortunately when it tries to read the atts later, it gives error:
  Caused by: java.lang.IllegalStateException: Attributes can only be used within the scope of startElement().</p>
  
  <p>Is there any fast, reliable way to store the attributes?
  Also, is there a better way to do this than constructing a new custom object StackElement for each start tag?</p>