Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中使用XQueryCompiler仅提取值_Java_Xml_Xml Parsing_Xquery_Saxon - Fatal编程技术网

在Java中使用XQueryCompiler仅提取值

在Java中使用XQueryCompiler仅提取值,java,xml,xml-parsing,xquery,saxon,Java,Xml,Xml Parsing,Xquery,Saxon,我使用以下代码从存储在字符串中的XML文件中获取一些结果。但是xquerycompiler要求我将它们封装到中。我能不能不把它们括起来,只把输出放在一个字符串中?这是我的密码: Configuration saxonConfig = new Configuration(); Processor processor = new Processor(saxonConfig); XQueryCompiler xqueryCompiler = proce

我使用以下代码从存储在字符串中的XML文件中获取一些结果。但是xquerycompiler要求我将它们封装到
中。我能不能不把它们括起来,只把输出放在一个字符串中?这是我的密码:

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());
Configuration saxonConfig=new Configuration();
处理器=新处理器(saxonConfig);
XQueryCompiler XQueryCompiler=processor.newXQueryCompiler();
XQueryExecutable xqueryExec=xqueryCompiler.compile(“{/book/chapter}”);
XQueryEvaluator xqueryEval=xqueryExec.load();
setSource(新SAXSource(新InputSource(新StringReader(xmltext)));
XdmDestination destination=新的XdmDestination();
xqueryEval.setDestination(目的地);
xqueryEval.run();
System.out.println(destination.getXdmNode());

为什么不将结果包装在“result”中,将元素返回到字符串中,然后使用简单的子字符串函数去掉前导的
和尾随的

我看不出有什么困难,但我不确定我是否完全理解需求。输入是什么,输出是什么?如果查询减少到
/book/chapter
,您会遇到什么故障?这是我得到的错误:“模块第1行错误,没有系统ID:只有一个根节点可以写入XDMDestation”。我的程序正在生成多个章节,但由于它们没有包含在根节点中,这就导致了问题。解决方案是什么?如果您不想将章节包装在元素节点(如result)中,可以使用XQuery文档节点{}构造函数将其包装在文档节点中。