1

当我运行以下

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

但评估失败:

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

这是一个有点胡说八道的例子,但我想要一些自包含的东西。这有什么问题?

4

1 回答 1

1

如果你想计算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);
于 2013-09-13T08:39:09.860 回答