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);