Learn XQuery |
Home:Learn XQuery:XQuery Tutorial:Performance Tips:Retrieving Query Results Retrieving Query ResultsDataDirect XQuery® is carefully designed to allow very large query results to be retrieved efficiently, and to allow incremental instantiation of query results, so that memory can also be used efficiently. If your query's results can be large, stream the results to an OutputStream or use SAX or StAX, so that retrieving the results does not introduce issues with memory or performance. Retrieving large query results as DOM can use large amounts of memory and significantly increase the time needed for processing queries. If you want to write your query results to an output stream or a file, the easiest way is to use the writeSequence() method of the result set to write directly to the stream, as shown in the following code. Example 11. Writing a Result Sequence to a Stream
XQSequence sequence = expression.executeQuery(query);
OutputStream os = new FileOutputStream("C:/temp/results.xml");
sequence.writeSequence(os);
Many XML programs process XML using SAX, and DataDirect XQuery® can write query results directly to a SAX event handler, as shown in the following code. Example 12. Writing to a SAX Event Handler
CustomSAXEventHandler eventHandler = new CustomSAXEventHandler();
sequence.writeSequenceToSAX(eventHandler);
For many kinds of programming, pull processing using StAX is both convenient and efficient. You can get a StAX stream from a result sequence using the getSequenceAsStream() method: Example 13. Retrieving Results as a StAX Stream
XMLStreamReader reader = sequence.getSequenceAsStream();
|
Try DataDirect XQuery® Free!Put the power, scalability, and performance of DataDirect XQuery® to work for you today! Our free trial lets you see for yourself how easy it is to build data integration applications that access relational, EDI, and other file formats as XML! Online Video Tutorials!Our easy-to-follow online video tutorials are a great way to get acquainted with the many features of DataDirect XQuery®. And if you like what you see, download a free copy today and try DataDirect XQuery® for yourself! Stay Informed!XQuery is one of the hottest XML technologies being developed today. Stay informed with vital news about standards, tools, and trends by signing up for the DataDirect XQuery® newsletter. |





