Project

Profile

Help

Bug #3056 ยป CompileLibraryTest.java

Test program showing message on System.err - Gunther Rademacher, 2016-12-01 17:42

 
package xquery;

import java.io.StringReader;

import javax.xml.transform.stream.StreamSource;

import com.saxonica.config.EnterpriseConfiguration;

import net.sf.saxon.lib.ModuleURIResolver;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.XQueryCompiler;
import net.sf.saxon.s9api.XQueryEvaluator;
import net.sf.saxon.s9api.XQueryExecutable;
import net.sf.saxon.trans.XPathException;

public class CompileLibraryTest {
public static void main(String[] args) throws Exception {
Processor processor = new Processor(new EnterpriseConfiguration());
XQueryCompiler compiler = processor.newXQueryCompiler();

String module = "module namespace m='M'; declare function m:f($a as node()){local-name($a)};";
// compiler.setModuleURIResolver(new ModuleURIResolver() {
// @Override
// public StreamSource[] resolve(String moduleURI, String baseURI, String[] locations) throws XPathException {
// StreamSource moduleSource = new StreamSource(new StringReader(module));
// moduleSource.setSystemId("M");
// return new StreamSource[]{moduleSource};
// }
// });

compiler.compileLibrary(module);

XQueryExecutable executable = compiler.compile("import module namespace m='M'; m:f(x)");
XQueryEvaluator evaluator = executable.load();
evaluator.setContextItem(processor.newDocumentBuilder().build(new StreamSource(new StringReader("<x/>"))));
evaluator.run(processor.newSerializer(System.out));
}
}
    (1-1/1)