gpt4 book ai didi

java - JDOM2 和 XPath

转载 作者:太空宇宙 更新时间:2023-11-04 07:24:25 25 4
gpt4 key购买 nike

当我运行以下命令时

XPathFactory xpathFactory = XPathFactory.instance();
XPathExpression<Double> query =
xpathFactory.compile("count(1)", Filters.fdouble());
List<Double> result = query.evaluate(new Element("test"));

但是评估失败:

无法计算表达式。查看原因原因:功能:计数

这是一个有点无意义的例子,但我想要一些独立的东西。这有什么问题吗?

最佳答案

如果您想计算 test 元素的数量,请尝试此操作;

Element root = new Element("test");
Document doc = new Document(root);

XPathFactory xpathFactory = XPathFactory.instance();
XPathExpression<Double> query = xpathFactory.compile("count(//test)", Filters.fdouble());
List<Double> result = query.evaluate(doc);

关于java - JDOM2 和 XPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18780881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com