InputStream stream = new ByteArrayInputStream(
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?><document><text> </document>"
.getBytes());
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLEventReader reader = factory.createXMLEventReader(stream);
StartDocument startdoc = (StartDocument) reader.nextEvent();
assertEquals("UTF-8", startdoc.getCharacterEncodingScheme());
assertEquals("1.0", startdoc.getVersion());
assertTrue(reader.hasNext());
XMLEvent event = reader.nextEvent();
assertTrue(event.isStartElement());
event = reader.nextEvent();
assertTrue(event.isCharacters());