/** * Run the query in pull mode. From Saxon 9.8 this method is identical to {@link #run(DynamicQueryContext, Result, Properties)} * * @param dynamicEnv the dynamic context for query evaluation * @param destination the Receiver to accept the query results *usually a serializer) * @throws XPathException if a dynamic error occurs during the evaluation * @deprecated since 9.8. */ public void pull(/*@NotNull*/ DynamicQueryContext dynamicEnv, /*@NotNull*/ Result destination, Properties outputProperties) throws XPathException { run(dynamicEnv, destination, outputProperties); }
exp.run(dynamicEnv, new StreamResult(destination), outputProps);
/** * Run the query in pull mode. From Saxon 9.8 this method is identical to {@link #run(DynamicQueryContext, Result, Properties)} * * @param dynamicEnv the dynamic context for query evaluation * @param destination the Receiver to accept the query results *usually a serializer) * @throws XPathException if a dynamic error occurs during the evaluation * @deprecated since 9.8. */ public void pull(/*@NotNull*/ DynamicQueryContext dynamicEnv, /*@NotNull*/ Result destination, Properties outputProperties) throws XPathException { run(dynamicEnv, destination, outputProperties); }
/** * Run the query in pull mode. From Saxon 9.8 this method is identical to {@link #run(DynamicQueryContext, Result, Properties)} * (supplying the default serialization properties from the configuration as the third argument) * @param dynamicEnv the dynamic context for query evaluation * @param destination the Receiver to accept the query results *usually a serializer) * @throws XPathException if a dynamic error occurs during the evaluation * @deprecated since 9.8. */ public void pull(DynamicQueryContext dynamicEnv, SequenceReceiver destination) throws XPathException { run(dynamicEnv, destination, getConfiguration().getDefaultSerializationProperties()); }
/** * Run the query in pull mode. From Saxon 9.8 this method is identical to {@link #run(DynamicQueryContext, Result, Properties)} * (supplying the default serialization properties from the configuration as the third argument) * @param dynamicEnv the dynamic context for query evaluation * @param destination the Receiver to accept the query results *usually a serializer) * @throws XPathException if a dynamic error occurs during the evaluation * @deprecated since 9.8. */ public void pull(DynamicQueryContext dynamicEnv, SequenceReceiver destination) throws XPathException { run(dynamicEnv, destination, getConfiguration().getDefaultSerializationProperties()); }
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; import net.sf.saxon.Configuration; import net.sf.saxon.om.DocumentInfo; import net.sf.saxon.query.DynamicQueryContext; import net.sf.saxon.query.StaticQueryContext; import net.sf.saxon.query.XQueryExpression; import org.xml.sax.InputSource; // inside a method Configuration config = new Configuration(); StaticQueryContext sqc = config.newStaticQueryContext(); DynamicQueryContext dqc = new DynamicQueryContext(config); String xq = "XQUERY_EXPRESSION"; try (InputStream xmlFileInput = new FileInputStream("data.xml"); OutputStream xmlFileOutput = new FileOutputStream("data-filtered.xml")) { XQueryExpression expression = sqc.compileQuery(xq); SAXSource source = new SAXSource(new InputSource(xmlFileInput)); DocumentInfo di = config.buildDocument(source); dqc.setContextItem(di); expression.run(dqc, new StreamResult(xmlFileOutput), null); } catch (Exception e) { System.err.println(e.getMessage()); }
exp.pull(dynamicEnv, new StreamResult(destination), outputProps); } else { exp.run(dynamicEnv, new StreamResult(destination), outputProps);
/** * Perform the query, sending the results to a specified destination. * <p>This method must not be used with an updating query.</p> * <p>This method is designed for use with a query that produces a single node (typically * a document node or element node) as its result. If the query produces multiple nodes, * the effect depends on the kind of destination. For example, if the result is an * <code>XdmDestination</code>, only the last of the nodes will be accessible.</p> * * @param destination The destination where the result document will be sent * @throws net.sf.saxon.s9api.SaxonApiException * if any dynamic error occurs during the query * @throws IllegalStateException if this is an updating query */ public void run(Destination destination) throws SaxonApiException { if (expression.isUpdateQuery()) { throw new IllegalStateException("Query is updating"); } try { Receiver out = getDestinationReceiver(destination); expression.run(context, out, null); destination.closeAndNotify(); } catch (TransformerException e) { throw new SaxonApiException(e); } }
/** * Perform the query, sending the results to a previously specified destination * @throws net.sf.saxon.s9api.SaxonApiException if any dynamic error occurs during the query * @throws IllegalStateException if no Destination has been supplied for the query results */ public void run() throws SaxonApiException { try { expression.run(context, destination.getReceiver(expression.getExecutable().getConfiguration()), null); } catch (TransformerException e) { throw new SaxonApiException(e); } }
/** * Perform the query, sending the results to a specified destination * @param destination The destination where the result document will be sent * @throws net.sf.saxon.s9api.SaxonApiException if any dynamic error occurs during the query */ public void run(Destination destination) throws SaxonApiException { try { expression.run(context, destination.getReceiver(expression.getExecutable().getConfiguration()), null); } catch (TransformerException e) { throw new SaxonApiException(e); } }
/** * Perform the query, sending the results to a specified destination. * <p>This method must not be used with an updating query.</p> * <p>This method is designed for use with a query that produces a single node (typically * a document node or element node) as its result. If the query produces multiple nodes, * the effect depends on the kind of destination. For example, if the result is an * <code>XdmDestination</code>, only the last of the nodes will be accessible.</p> * * @param destination The destination where the result document will be sent * @throws net.sf.saxon.s9api.SaxonApiException * if any dynamic error occurs during the query * @throws IllegalStateException if this is an updating query */ public void run(Destination destination) throws SaxonApiException { if (expression.isUpdateQuery()) { throw new IllegalStateException("Query is updating"); } try { Receiver out = getDestinationReceiver(destination); expression.run(context, out, null); destination.closeAndNotify(); } catch (TransformerException e) { throw new SaxonApiException(e); } }