title: How to get element only elements with values Stax
body: <p>I'm trying to get only elements that have text, ex xml :</p>
  
  <pre><code>&lt;root&gt;
        &lt;Item&gt;
          &lt;ItemID&gt;4504216603&lt;/ItemID&gt;
          &lt;ListingDetails&gt;
            &lt;StartTime&gt;10:00:10.000Z&lt;/StartTime&gt;
            &lt;EndTime&gt;10:00:30.000Z&lt;/EndTime&gt;
            &lt;ViewItemURL&gt;http://url&lt;/ViewItemURL&gt;
              ....
             &lt;/item&gt; 
  </code></pre>
  
  <p>It should print </p>
  
  <pre><code>Element Local Name:ItemID
  Text:4504216603
  Element Local Name:StartTime
  Text:10:00:10.000Z
  Element Local Name:EndTime
  Text:10:00:30.000Z
  Element Local Name:ViewItemURL
  Text:http://url
  </code></pre>
  
  <p>This code prints also root, item etc. Is it even possible, it must be I just can't google it.</p>
  
  <pre><code>XMLInputFactory inputFactory = XMLInputFactory.newInstance();
  InputStream input = new FileInputStream(new File("src/main/resources/file.xml"));
  XMLStreamReader xmlStreamReader = inputFactory.createXMLStreamReader(input);
  
  while (xmlStreamReader.hasNext()) {
      int event = xmlStreamReader.next();
  
      if (event == XMLStreamConstants.START_ELEMENT) {
      System.out.println("Element Local Name:" + xmlStreamReader.getLocalName());
      }
  
      if (event == XMLStreamConstants.CHARACTERS) {
                          if(!xmlStreamReader.getText().trim().equals("")){
                          System.out.println("Text:"+xmlStreamReader.getText().trim());
                          }
                  }
  
              }
  </code></pre>
  
  <p><strong>Edit incorrect behaviour</strong> :</p>
  
  <pre><code>    Element Local Name:root
      Element Local Name:item
      Element Local Name:ItemID
      Text:4504216603
      Element Local Name:ListingDetails
      Element Local Name:StartTime
      Text:10:00:10.000Z
      Element Local Name:EndTime
      Text:10:00:30.000Z
      Element Local Name:ViewItemURL
      Text:http://url
  </code></pre>
  
  <p>I don't want that root and other nodes which don't have text to be printed, just the output which I wrote above. thank you</p>