如何使用 saxon 9.2he 在 java 中设置 xquery 上下文文档? [英] how to set xquery context document in java using saxon 9.2he?

查看:50
本文介绍了如何使用 saxon 9.2he 在 java 中设置 xquery 上下文文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何执行一个简单的这个 xquery,比如这个

how do I execute a simple this xquery, such as this

for $elem in /root/element()
return 
    $elem

在不使用 fn:doc 的情况下使用 java 的 xml 文件?

on an xml file using java without using fn:doc?

我一直在XPDY0002:轴步骤 child::element(xml, xs:anyType) 的上下文项未定义

I keep getting XPDY0002: The context item for axis step child::element(xml, xs:anyType) is undefined

--概要:我需要一个简单的解决方案来加载 xml 文件、加载 xquery 并进行处理

--the rundown: I need a simple solution to load an xml file, load an xquery and process

推荐答案

这是我找到的最简单的方法,但我希望使用 XQStaticContext 将 contextDocument绑定"到表达式.

here is the simplest way I found to do it however I was hoping to use XQStaticContext to "bind" the contextDocument to the expression.

XQDataSource ds = new SaxonXQDataSource();
XQConnection xqjc = ds.getConnection();
XQPreparedExpression xqje = xqjc.prepareExpression(new FileInputStream("xml\\foo.xquery"));

XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = factory.createXMLStreamReader(new FileReader("xml\\foo.xml"));

xqje.bindDocument(XQConstants.CONTEXT_ITEM,streamReader, xqjc.createDocumentType());

XQResultSequence xqjs  = xqje.executeQuery();

xqjs.writeSequence(System.out, null);

这篇关于如何使用 saxon 9.2he 在 java 中设置 xquery 上下文文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆