@Override public ValidationResult validate(final String subject, final String input, final ValidationContext validationContext) { try { final Processor proc = new Processor(false); final XQueryCompiler comp = proc.newXQueryCompiler(); String error = null; try { comp.compile(input); } catch (final Exception e) { error = e.toString(); } return new ValidationResult.Builder().input(input).subject(subject).valid(error == null).explanation(error).build(); } catch (final Exception e) { return new ValidationResult.Builder().input(input).subject(subject).valid(false) .explanation("Unable to initialize XQuery engine due to " + e.toString()).build(); } } }
final XQueryCompiler comp = proc.newXQueryCompiler();
public XQueryCompiler getXQueryCompiler () { XQueryCompiler xqueryCompiler = processor.newXQueryCompiler(); for (java.util.Map.Entry<String, String> binding : namespaceBindings.entrySet()) { xqueryCompiler.declareNamespace(binding.getKey(), binding.getValue()); } xqueryCompiler.declareNamespace("lux", FunCall.LUX_NAMESPACE); return xqueryCompiler; }
private String getSchemaTNS(XdmItem schema) throws SaxonApiException { XQueryEvaluator e = processor.newXQueryCompiler().compile("declare namespace xsd = \"http://www.w3.org/2001/XMLSchema\"; xsd:string(xsd:schema/@targetNamespace)").load(); e.setContextItem(schema); XdmValue v = e.evaluate(); if (v instanceof XdmEmptySequence) return null; else return v.toString(); }
/** * 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(); }
fl = ps.getFunctionLibrary(); } else { XQueryCompiler xqcomp = processor.newXQueryCompiler(); StaticQueryContext sqc = xqcomp.getUnderlyingStaticContext(); sqc.compileLibrary(connection.getInputStream(), "utf-8");
/** * 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(); }
fl = ps.getFunctionLibrary(); } else { XQueryCompiler xqcomp = processor.newXQueryCompiler(); StaticQueryContext sqc = xqcomp.getUnderlyingStaticContext(); sqc.compileLibrary(connection.getInputStream(), "utf-8");
XQueryCompiler xqueryCompiler = proc.newXQueryCompiler(); xqueryCompiler.setEncoding(CharEncoding.UTF_8);
@Override public ValidationResult validate(final String subject, final String input, final ValidationContext validationContext) { try { final Processor proc = new Processor(false); final XQueryCompiler comp = proc.newXQueryCompiler(); String error = null; try { comp.compile(input); } catch (final Exception e) { error = e.toString(); } return new ValidationResult.Builder().input(input).subject(subject).valid(error == null).explanation(error).build(); } catch (final Exception e) { return new ValidationResult.Builder().input(input).subject(subject).valid(false) .explanation("Unable to initialize XQuery engine due to " + e.toString()).build(); } } }
XQueryCompiler xqcomp = qtproc.newXQueryCompiler(); xqcomp.setModuleURIResolver(runtime.getResolver()); XQueryExecutable xqexec = xqcomp.compile(queryexpr);
XQueryCompiler xqcomp = qtproc.newXQueryCompiler(); xqcomp.setModuleURIResolver(runtime.getResolver()); XQueryExecutable xqexec = xqcomp.compile(queryexpr);
/** * 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(); } }
XQueryCompiler compiler = processor.newXQueryCompiler(); compiler.setErrorListener(new DefaultErrorListener()); compiler.setCompileWithTracing(isTracing);
XQueryCompiler compiler = processor.newXQueryCompiler(); compiler.setErrorListener(new DefaultErrorListener()); compiler.setCompileWithTracing(isTracing);
@BeforeMethod public void setUp() throws SaxonApiException { MockitoAnnotations.initMocks(this); given(processorFactory.createProcessor()).willReturn(processor); given(processor.newXQueryCompiler()).willReturn(xQueryCompiler); given(xQueryCompiler.compile(QUERY)).willReturn(xQueryExecutable); given(xQueryExecutable.load()).willReturn(xQueryEvaluator); given(inputSourceFactory.createInputSource(INPUT)).willReturn(inputSource); given(saxSourceFactory.createSAXSource(inputSource)).willReturn(saxSource); given(byteArrayOutputStreamFactory.createByteArrayOutputStream()).willReturn(outputStream); }
public static void serialize(XProcRuntime xproc, Vector<XdmNode> nodes, Serializer serializer) throws SaxonApiException { Processor qtproc = xproc.getProcessor(); XQueryCompiler xqcomp = qtproc.newXQueryCompiler(); xqcomp.setModuleURIResolver(xproc.getResolver());
public static void serialize(XProcRuntime xproc, Vector<XdmNode> nodes, Serializer serializer) throws SaxonApiException { Processor qtproc = xproc.getProcessor(); XQueryCompiler xqcomp = qtproc.newXQueryCompiler(); xqcomp.setModuleURIResolver(xproc.getResolver());
XQueryCompiler xqcomp = qtproc.newXQueryCompiler(); xqcomp.setBaseURI(root.getBaseURI());
XQueryCompiler xqcomp = qtproc.newXQueryCompiler(); xqcomp.setBaseURI(root.getBaseURI());