document.mark(4);
boolean isFastInfosetDocument = Decoder.isFastInfosetDocument(document);
document.reset();
if (isFastInfosetDocument) {
StAXDocumentParser parser = new StAXDocumentParser();
parser.setInputStream(document);
SAXEventSerializer ses = new SAXEventSerializer(events);
StAX2SAXReader reader = new StAX2SAXReader(parser, ses);
reader.setLexicalHandler(ses);
reader.adapt();
} else {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
SAXParser parser = parserFactory.newSAXParser();
SAXEventSerializer ses = new SAXEventSerializer(events);
parser.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, ses);
parser.parse(document, ses);
}
}