如何使用 saxon 9.2he 在 java 中设置 xquery 上下文文档?

发布于 2024-09-07 09:52:58 字数 259 浏览 4 评论 0原文

执行简单的此 xquery

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

如何在不使用 fn:doc 的情况下使用 java 在 xml 文件上

?我不断得到 XPDY0002:轴步骤 child::element(xml, xs:anyType) 的上下文项未定义

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

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

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁梦 2024-09-14 09:52:58

这是我发现的最简单的方法,但是我希望使用 XQStaticContext 将 contextDocument“绑定”到表达式。

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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文