title: Ignoring comments with StaX
body: <p>Using the following code, I'm successfully reading XML files. However when a comment appears in the middle of a node, the reader is discarding the remainder of the node. For example:</p>
  
  <pre><code>&lt;text&gt;thisismy&lt;!--comment--&gt;document&lt;/text&gt;
  </code></pre>
  
  <p>would result in a return string of "thisismy" and nothing else.</p>
  
  <p>I had a similar problem earlier when I'd encounter special chars like <kbd>&amp;</kbd> and setting the <code>XMLInputFactory</code> to <code>isCoalescing=true</code> fixed that. I'm guessing I've encountered a related feature.</p>
  
  <p>I need to be able to process such documents elegantly. Can anyone suggest how I might work around such interruptions?</p>
  
  <pre><code>try {
          XMLInputFactory factory = XMLInputFactory.newInstance();
          factory.setProperty("javax.xml.stream.isCoalescing", true);
          XMLEventReader eventReader =
                  factory.createXMLEventReader(new FileReader(fileName));
  
          while(eventReader.hasNext()) {
              XMLEvent event = eventReader.nextEvent();
  
              switch(event.getEventType()) {
  
                  case XMLStreamConstants.START_ELEMENT:
                      StartElement startElement = event.asStartElement();
                      String qName = startElement.getName().getLocalPart();
  
                      if (qName.equalsIgnoreCase("page")) {
                          page = new DocumentPage();
                          Iterator&lt;Attribute&gt; attributes = startElement.getAttributes();
                          while(attributes.hasNext())
                          {
                              Attribute attribute = attributes.next();
                              switch (attribute.getName().toString().toLowerCase()) {
                                  case "index" :
                                      pageIndex = attribute.getValue();
                                      page.setPageIndex(pageIndex);
                                      break;
  </code></pre>