org.w3c.tidy5.premium.ExecXquery Maven / Gradle / Ivy
package org.w3c.tidy5.premium;
import org.w3c.tidy5.premium.XQPCleaner.ClearRule;
import net.sf.saxon.om.TreeModel;
import net.sf.saxon.s9api.DocumentBuilder;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XQueryCompiler;
import net.sf.saxon.s9api.XQueryEvaluator;
import net.sf.saxon.s9api.XQueryExecutable;
import net.sf.saxon.s9api.XdmNode;
public class ExecXquery {
public static ExecXquery me() {
return new ExecXquery();
}
public String runIt(XdmNode xdmNode, ClearRule rule) throws Exception {
XQueryEvaluator evaluator = (XQueryEvaluator) rule.iterable;
evaluator.setContextItem(xdmNode);
evaluator.run();
return xdmNode.toString();
}
public String runIt(String domString, String rulestring) throws Exception {
DocumentBuilder builder = Executor.PROCESSOR.newDocumentBuilder();
builder.setTreeModel(TreeModel.LINKED_TREE);
XdmNode xdmNode = builder.build(StringSource.newMe(domString));
XQueryCompiler queryCompiler = Executor.PROCESSOR.newXQueryCompiler();
queryCompiler.setUpdatingEnabled(true);
XQueryExecutable executable = queryCompiler.compile(rulestring);
XQueryEvaluator evaluator = executable.load();
evaluator.setContextItem(xdmNode);
evaluator.run();
return xdmNode.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy