文件名称:xquery与java使用
文件大小:4KB
文件格式:JAVA
更新时间:2016-05-12 04:58:17
java xquery
java中使用xquery的例子 String fileString = "src/study/xquery/cd_catalog.xml"; //查询语句 String query = " for $s in //CD/TITLE " + " return $s"; //生产文档对象 Document document = getDocument(fileString); Configuration configuration = new Configuration(); StaticQueryContext context = new StaticQueryContext(configuration, false); //查询表达式对象 XQueryExpression expression = null; try { expression = context.compileQuery(query); DynamicQueryContext context2 = new DynamicQueryContext(configuration); context2.setContextItem(new DocumentWrapper(document,null,configuration)); final Properties props = new Properties(); props.setProperty(OutputKeys.METHOD, "xml"); props.setProperty(OutputKeys.INDENT, "yes"); //执行查询,并输出查询结果 expression.run(context2, new StreamResult(System.out), props); } catch (XPathException e) { // TODO Auto-generated catch block e.printStackTrace(); }