加载预编译的可执行文件
您可以使用 XCompilationFactory 接口及其各种加载方法,加载预编译表达式、查询或样式表。这些加载方法加载 Java™ 类,并分别返回 XPathExecutable、XQueryExecutable 或 XSLTExecutable 对象。
过程
示例
以下为加载预编译 XPath 表达式的基本示例。
// Create the factory
XFactory factory = XFactory.newInstance();
// Get the compilation factory
XCompilationFactory compileFactory = factory.getCompilationFactory();
// Create the compilation parameters
XCompilationParameters params = compileFactory.newCompilationParameters("MyXPath");
params.setPackageName( "org.example.myxpath");
// Load the executable
XPathExecutable executable = compileFactory.loadXPath(params);
// Create the input source
StreamSource input = new StreamSource("simple.xml");
// Execute the XPath expression
XSequenceCursor cursor = executable.execute(input);
Appropriate load methods are available for XQuery and XSLT as well.