如何在Java中使用Saxon XPath处理器w / o编码 [英] How to use Saxon XPath processor w/o coding in Java

查看:423
本文介绍了如何在Java中使用Saxon XPath处理器w / o编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我可以做一些XSL样式表,然后使用它作为参数选项的模板与评估XPath表达式与Saxon XSLT处理器在命令行,如:

I guess I could make some XSL stylesheet, then use it as a template with parameter option to evaluate XPath expression with Saxon XSLT processor on command line, like:

<xsl:template match="/">
  <xsl:copy-of select="saxon:evaluate($xpath-param)"/>
</xsl:template>

还有一种可能性是使用他们的Java API: http://www.saxonica.com/documentation/xpath-api/intro.xml 但我不知道Java

Also other possibility is to use their Java API: http://www.saxonica.com/documentation/xpath-api/intro.xml but I don't know Java

有没有办法让Saxon从命令行评估XPath表达式?

如果可能,shell脚本也是足够的

Is there any way to make Saxon evaluate XPath expression from command line?
Shell script would be sufficient, too, if possible

更新:

浏览Saxon 文档,我发现了 XPathExample 示例。不幸的是我不能使用它

Update:
Browsing Saxon documentation, I found out about XPathExample sample. Unfortunately I can't make use of it

推荐答案

您可以从命令行运行Saxon(XQuery)。您可以通过使用 -q 指向具有XPath / XQuery的文件来执行此操作,也可以直接使用 -qs

You can run Saxon (XQuery) from the command line. You can do this by pointing to a file that has the XPath/XQuery using -q or you can pass the query string directly using -qs.

下面是使用 -qs 来处理简单XPath的示例:

Here's an example of using -qs to process a simple XPath:

input.xml

<a>
  <b id="x"/>
  <b id="z"/>
  <b id="x"/>
</a>

Saxon命令行(我用Saxon9- HE测试) / p>

Saxon command line (I used Saxon9-HE to test with)

java -cp "saxon9he.jar" net.sf.saxon.Query -s:"input.xml" -qs:"/a/b[@id='x']" -o:"results.xml"

results.xml

results.xml

<b id="x"/><b id="x"/>

注意:我可以通过更改 -qs 为这样: -qs:< results> {/ a / b [@ id ='x']}< / results&

Note: I could've made my output well-formed by changing the -qs to something like this: -qs:"<results>{/a/b[@id='x']}</results>".

有关更多命令行选项,请查看: http://www.saxonica.com/html/documentation/using-xquery/commandline.html

For more command line options, look here: http://www.saxonica.com/html/documentation/using-xquery/commandline.html

这篇关于如何在Java中使用Saxon XPath处理器w / o编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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