@Override public void process(final InputStream rawIn) throws IOException { try (final InputStream in = new BufferedInputStream(rawIn)) { XQueryEvaluator qe = slashExpression.load(); qe.setSource(new SAXSource(xmlReader, new InputSource(in))); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setNamespaceAware(true); Document dom = dfactory.newDocumentBuilder().newDocument(); qe.run(new DOMDestination(dom)); XdmNode rootNode = proc.newDocumentBuilder().wrap(dom); sourceRef.set(rootNode); } catch (final Exception e) { error.set(e); } } });
@Override public void process(final InputStream rawIn) throws IOException { try (final InputStream in = new BufferedInputStream(rawIn)) { XQueryEvaluator qe = slashExpression.load(); qe.setSource(new SAXSource(xmlReader, new InputSource(in))); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setNamespaceAware(true); Document dom = dfactory.newDocumentBuilder().newDocument(); qe.run(new DOMDestination(dom)); XdmNode rootNode = proc.newDocumentBuilder().wrap(dom); sourceRef.set(rootNode); } catch (final Exception e) { error.set(e); } } });
eval.setSource(content);
/** * Evaluates an XQuery 1.0 expression using the Saxon s9api interfaces. * * @param source The XML Source. * @param query The query expression. * @param nsBindings A collection of namespace bindings required to evaluate * the query, where each entry maps a namespace URI (key) to a prefix * (value). * @return An XdmValue object representing a value in the XDM data model. * @throws SaxonApiException If an error occurs while evaluating the query * (this always wraps some other underlying exception). */ public static XdmValue evaluateXQuery(Source source, String query, Map<String, String> nsBindings) throws SaxonApiException { Processor proc = new Processor(false); XQueryCompiler xqCompiler = proc.newXQueryCompiler(); if (null != nsBindings) { for (String nsURI : nsBindings.keySet()) { xqCompiler.declareNamespace(nsBindings.get(nsURI), nsURI); } } XQueryExecutable xqExec = xqCompiler.compile(query); XQueryEvaluator xqEval = xqExec.load(); xqEval.setSource(source); return xqEval.evaluate(); }
/** * Evaluates an XQuery 1.0 expression using the Saxon s9api interfaces. * * @param source * The XML Source. * @param query * The query expression. * @param nsBindings * A collection of namespace bindings required to evaluate the * query, where each entry maps a namespace URI (key) to a prefix * (value). * @return An XdmValue object representing a value in the XDM data model. * @throws SaxonApiException * If an error occurs while evaluating the query (this always * wraps some other underlying exception). */ public static XdmValue evaluateXQuery(Source source, String query, Map<String, String> nsBindings) throws SaxonApiException { Processor proc = new Processor(false); XQueryCompiler xqCompiler = proc.newXQueryCompiler(); if (null != nsBindings) { for (String nsURI : nsBindings.keySet()) { xqCompiler.declareNamespace(nsBindings.get(nsURI), nsURI); } } XQueryExecutable xqExec = xqCompiler.compile(query); XQueryEvaluator xqEval = xqExec.load(); xqEval.setSource(source); return xqEval.evaluate(); }
/** * Executes a given XQuery expression on the given XML. * @param xml is the XQuery data source * @param query is the query expression * @return with the query result as String * @throws SaxonApiException was thrown when the XQuery execution is failed */ public String evaluateXQuery(final String xml, final String query) throws SaxonApiException { Processor processor = processorFactory.createProcessor(); XQueryCompiler xqueryCompiler = processor.newXQueryCompiler(); xqueryCompiler.setErrorListener(errorListener); XQueryExecutable xqueryExec = xqueryCompiler.compile(query); XQueryEvaluator xqueryEval = xqueryExec.load(); xqueryEval.setErrorListener(errorListener); SAXSource requestXml = saxSourceFactory.createSAXSource(inputSourceFactory.createInputSource(xml)); xqueryEval.setSource(requestXml); ByteArrayOutputStream baos = byteArrayOutputStreamFactory.createByteArrayOutputStream(); Serializer ser = serializerFactory.createSerializer(baos); xqueryEval.setDestination(ser); xqueryEval.run(); return baos.toString(); } }
NodeInfo doc = sourceTreeBuilder.getCurrentRoot(); doc.getTreeInfo().setSpaceStrippingRule(controller.getSpaceStrippingRule()); setSource(doc); sourceTreeBuilder = null; if (doc == null) {
NodeInfo doc = sourceTreeBuilder.getCurrentRoot(); doc.getTreeInfo().setSpaceStrippingRule(controller.getSpaceStrippingRule()); setSource(doc); sourceTreeBuilder = null; if (doc == null) {