title: What are best algorithms/patterns to read xml files using [java] sax?
body: <p>Let's suppose we have the following xml</p>
  
  <pre><code>&lt;books&gt;
     &lt;book&gt;
        &lt;id&gt;...&lt;/id&gt;  
        &lt;title&gt;...&lt;/title&gt;
        &lt;references&gt;
           &lt;book&gt;
             &lt;id&gt;...&lt;/id&gt;  
             &lt;title&gt;...&lt;/title&gt;
           &lt;/book&gt;
        &lt;/references&gt;            
        &lt;authors&gt;
           &lt;author&gt;
             &lt;id&gt;...&lt;/id&gt;
             &lt;name&gt;...&lt;/name&gt;
              &lt;written-books&gt;
                &lt;book&gt;
                &lt;id&gt;...&lt;/id&gt;  
                &lt;title&gt;...&lt;/title&gt;
                &lt;/book&gt;
              &lt;/written-books&gt;
           &lt;/author&gt;
        &lt;/authors&gt;
     &lt;book&gt;
  &lt;/books&gt;
  </code></pre>
  
  <p>What I do now is to use booleans to find out in what sections we are (book,references,authors,written-books). I do this on starte/end element event ,After that on characters event I check</p>
  
  <pre><code>if (qName.equals("id"){
     if (writtenBooks){
     }else if (authors){
     }else if (references){
     }else{
     }
  }else if ("title")...
  </code></pre>
  
  <p>But it doesn't seem to be too elegant. Is there a better solution?</p>