title: Can the Java streaming XML parser distinguish empty element from self-closing empty element?
body: <p>Can the Java streaming XML parser, i.e. <a href="https://docs.oracle.com/javase/8/docs/api/javax/xml/stream/XMLEventReader.html" rel="nofollow noreferrer">javax.xml.stream.XMLEventReader</a> distinguish an empty element </p>
  
  <pre><code>&lt;document&gt;
    &lt;empty&gt;&lt;/empty&gt;
  &lt;document&gt;
  </code></pre>
  
  <p>from a self-closing empty element?</p>
  
  <pre><code>&lt;document&gt;
    &lt;empty/&gt;
  &lt;document&gt;
  </code></pre>
  
  <p>Let's suppose we parse both of the above xml fragments and print the eventType and the event itself, just like this:</p>
  
  <pre><code>System.out.println("eventType:" + event.getEventType() + "; element:"+event.toString());
  </code></pre>
  
  <p>Both of the above fragments will produce the exact same result:</p>
  
  <pre><code>eventType:7; element:&lt;?xml version="null" encoding='null' standalone='no'?&gt;
  eventType:1; element:&lt;document&gt;
  eventType:4; element:   
  eventType:1; element:&lt;empty&gt;
  eventType:2; element:&lt;/empty&gt;
  eventType:2; element:&lt;/document&gt;
  eventType:8; element:ENDDOCUMENT 
  </code></pre>
  
  <p>Just to give some context, what we want to achieve is, we want to rewrite some parts of the xml based on some rules, but want to preserve other parts exactly as they are, that is, we want to keep empty elements in their original form, even though the two forms are semantically the same. If we have a normal empty element (1st example), we want to keep it that way, if we have a self-closing empty element, we want to write a self-closing element in the result as well. Can we achieve this goal with <a href="https://docs.oracle.com/javase/8/docs/api/javax/xml/stream/XMLEventReader.html" rel="nofollow noreferrer">javax.xml.stream.XMLEventReader</a>?</p>