title: State pattern with SAX
body: <p>I have to parse some xml with java SAX parser. As I was busy, I saw that the state pattern could  be used here.</p>
  
  <p>There are clear states and state transitions defined, resembling the structure of the xml document. </p>
  
  <p>To implement the state pattern, I have to define a interface (or abstract class). The most obvious interface methods would be:</p>
  
  <pre><code>public void startElement(String elementName);
  public void endElement(String elementName);
  </code></pre>
  
  <p>But the problem I encounter is how to return the information. I need the information from several levels in the xml document in one structure. </p>
  
  <p>This is a part of the xml document</p>
  
  <pre><code>&lt;chessboard&gt;
       &lt;white&gt;
           &lt;king&gt;
                &lt;position&gt;
                    &lt;x&gt;e&lt;/x&gt;
            &lt;y&gt;1&lt;/y&gt;
                &lt;/position&gt;
           &lt;/king&gt;
           &lt;pawns&gt;
               &lt;pawn id="1"&gt;
                    &lt;position&gt;
                        &lt;x&gt;e&lt;/x&gt;
                &lt;y&gt;2&lt;/y&gt;
                    &lt;/position&gt;
               &lt;/pawn&gt;
               &lt;pawn id="1"&gt;
                    &lt;position&gt;
                        &lt;x&gt;f&lt;/x&gt;
                &lt;y&gt;2&lt;/y&gt;
                    &lt;/position&gt;
               &lt;/pawn&gt;
           &lt;/pawns&gt;
      &lt;/white&gt;
  &lt;/chessboard&gt;
  </code></pre>
  
  <p>Is my assumption right that the state patterns fits here? And if so, what is the best way to implement it here?</p>