code: private final void fireEvents()
          throws IOException, SAXException, XMLStreamException
      {
          // First we are in prolog:
          int type;
  
          /* Need to enable lazy parsing, to get DTD start events before
           * its content events. Plus, can skip more efficiently too.
           */
          mConfig.doParseLazily(false);
  
          while ((type = mScanner.next()) != XMLStreamConstants.START_ELEMENT) {
              fireAuxEvent(type, false);
          }
  
          // Now just starting the tree, need to process the START_ELEMENT
          fireStartTag();
  
          int depth = 1;
          while (true) {
              type = mScanner.next();
              if (type == XMLStreamConstants.START_ELEMENT) {
                  fireStartTag();
                  ++depth;
              } else if (type == XMLStreamConstants.END_ELEMENT) {
                  mScanner.fireSaxEndElement(mContentHandler);
                  if (--depth < 1) {
                      break;
                  }
              } else if (type == XMLStreamConstants.CHARACTERS) {
                  mScanner.fireSaxCharacterEvents(mContentHandler);
              } else {
                  fireAuxEvent(type, true);
              }
          }
  
          // And then epilog:
          while (true) {
              type = mScanner.next();
              if (type == XMLStreamConstants.END_DOCUMENT) {
                  break;
              }
              if (type == XMLStreamConstants.SPACE) {
                  // Not to be reported via SAX interface (which may or may not
                  // be different from Stax)
                  continue;
              }
              fireAuxEvent(type, false);
          }
      }
docs: This is the actual "tight event loop" that will send all events
  between start and end document events. Although we could
  use the stream reader here, there's not much as it mostly
  just forwards requests to the scanner: and so we can as well
  just copy the little code stream reader's next() method has.