The default StAX parser does not produce the correct events when the input document is:
<?xml-stylesheet href="bar.xsl" type="text/xsl"?>
<foo/>
In this case, the XMLStreamReader (com.sun.xml.internal.stream.XMLInputFactoryImpl) starts on a PROCESSING_INSTRUCTION event. Instead, it should start on a START_DOCUMENT event.
From JSR 173, 1.0, Section 5.1, XMLStreamReader:
"At any moment in time an XMLStreamReader instance has a current event that the methods of the interface access. Instances are created in the START_DOCUMENT state and this is set to the current event type."
Here is a reproducer:
---------- BEGIN SOURCE ----------
import java.io.StringReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamReader;
public class TestStAX {
public static void main(String[] args) throws Exception {
String xml = "<?xml-stylesheet href=\"bar.xsl\" type=\"text/xsl\"?>" +
"<foo/>";
XMLInputFactory factory = XMLInputFactory.newFactory();
// class com.sun.xml.internal.stream.XMLInputFactoryImpl
System.err.println(factory.getClass());
XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(xml));
// prints false, should print true
System.err.println(reader.getEventType() == XMLStreamConstants.START_DOCUMENT);
// prints true, should print false
System.err.println(reader.getEventType() == XMLStreamConstants.PROCESSING_INSTRUCTION);
// From JSR 173, 1.0, Section 5.1, XMLStreamReader:
// "At any moment in time an XMLStreamReader instance has a current event that the
// methods of the interface access. Instances are created in the START_DOCUMENT
// state and this is set to the current event type."
}
}
---------- END SOURCE ----------