【发布时间】:2013-03-28 14:38:13
【问题描述】:
我正在使用以下代码从存储在字符串中的 XML 文件中获取一些结果。但是 xquerycompiler 要求我将它们包含在<result></result> 中。我可以不将它们括起来而只将输出放在一个字符串中吗?这是我的代码:
Configuration saxonConfig = new Configuration();
Processor processor = new Processor(saxonConfig);
XQueryCompiler xqueryCompiler = processor.newXQueryCompiler();
XQueryExecutable xqueryExec = xqueryCompiler.compile("<result>{/book/chapter}</result>");
XQueryEvaluator xqueryEval = xqueryExec.load();
xqueryEval.setSource(new SAXSource(new InputSource(new StringReader(xmltext))));
XdmDestination destination = new XdmDestination();
xqueryEval.setDestination(destination);
xqueryEval.run();
System.out.println(destination.getXdmNode());
【问题讨论】:
-
我看不出有什么困难,但我不确定我是否完全理解这个要求。输入是什么,你想要什么输出?如果查询减少到
/book/chapter,你会遇到什么失败? -
这是我得到的错误:“module with no systemId 第 1 行出错:只能将单个根节点写入 XdmDestination”。我的程序正在生成多个章节,但由于它们没有包含在根节点中,因此会导致问题。解决办法是什么?
-
如果您不想将章节包装在诸如 result 这样的元素节点中,您可以使用 XQuery document-node{} 构造函数将它们包装在文档节点中。
标签: java xml xml-parsing xquery saxon