title: How to catch Attribute-events with a StAX XML-parser?
body: <p>I try to parse an XML file with a StAX XML-parser. It give me <code>START_ELEMENT</code> and <code>END_DOCUMENT</code> events but no <code>ATTRIBUTE</code> events. How can I receive <code>ATTRIBUTE</code> events with the StAX parser?</p>
  
  <p>My XML:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;posts&gt;
          &lt;row name="Jonas"/&gt;
          &lt;row name="John"/&gt;
      &lt;/posts&gt;
  </code></pre>
  
  <p>My StAX XML-parser:</p>
  
  <pre><code>public class XMLParser {
  
      public void parseFile(String filename) {
          XMLInputFactory2 xmlif = (XMLInputFactory2) XMLInputFactory2.newInstance();
          xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
          xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
          xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
          xmlif.configureForSpeed();
  
          XMLStreamReader2 xmlr = (XMLStreamReader2) 
                  xmlif.createXMLStreamReader(new FileInputStream(filename));
  
                  int eventType;
                  while(xmlr.hasNext()) {
                      eventType = xmlr.next();
                      switch(eventType) {
                      case XMLStreamConstants.START_ELEMENT: 
                          if(xmlr.getName().toString().equals("row")) {
                              System.out.println("row");
                          }
                          break;
                      case XMLStreamConstants.ATTRIBUTE: 
                          System.out.println("Attribute");
                          break;
                      case XMLStreamConstants.END_DOCUMENT:
                          System.out.println("END");
                          xmlr.close();
                          break;
                      }
                  }
  
      }
  
      public static void main(String[] args) {
          XMLParser p = new XMLParser();
          String filename = "data/test.xml";
          p.parseFile(filename);
      }
  
  }
  </code></pre>