}
}
private static void invokeQueryPushMode(InputStream input, URI baseUri) throws XQueryException,
XMLStreamException {
XQueryProcessor proc = new XQueryProcessor();
// #1 parse a query
XQueryModule module = proc.parse(input);
// prepare a result handler (StAX)
Writer writer = new StringWriter();
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter streamWriter = factory.createXMLStreamWriter(writer);
XQEventReceiver handler = new StAXSerializer(streamWriter);
// #2 execute the compiled expression using ``push'' mode
// In push mode, the result is directed to the events.
proc.execute(module, handler);
streamWriter.flush(); // flushing is required
System.out.println(writer.toString());
}