title: More generic way to parse XML from Java in a streaming fashion?
body: <p>I need to efficiently parse potentially very large XML files (and hence cannot put the whole file in memory).  As such I've looked into streaming techniques like XMLStreamReader, however these appear to be very low-level and produce very hard-coded code:</p>
  
  <pre><code>   event = parser.next();
     switch (event)
     {
      case XMLStreamConstants.START_ELEMENT:
           elementName = parser.getLocalName();
           if (elementName.equals("name")){
               state = FOUND_A_NAME;
           }else if (elementName.equals("address")){
               state = FOUND_AN_ADDRESS;                      
           }
      ETC...
      }
  </code></pre>
  
  <p>I am looking for a way to do this without so tightly coupling the parser with the thing to parse, and in addition, this code just does not feel right.  It seems like this should be more truly event-oriented.</p>
  
  <p>Any advice?</p>