一些根对象具有字段MyCollection myCollection。类MyCollection实现Collection接口。通过调用someService().getName()可以获得元素的名称,这就是我创建Rules类的原因。
context.getValue("/myCollection");返回myCollection - OK
context.getValue("//myCollection");返回myCollection - OK
context.getValue("/myCollection/.[rules:getName() = 'secondName']");返回IMyNode的实例,someService().getName()返回"secondName“- OK
在context.getValue("/myCollection//.[rules:getName() = 'secondName']");行之后,不执行下一行。也没有例外,也没有设置宽松的模式。我不明白这是怎么回事。Rules类的第8行打印"POINTER SET ON /myCollection[1]"。我想在这个例子中得到的元素在/myCollection[2]中。
元素的名称就是在这里得到的。我认为这门课是对的。
public class Rules {
public static String getName(ExpressionContext context){
Pointer pointer = context.getContextNodePointer();
if(pointer == null){
return "";
} else {
if(pointer.getValue() instanceof IMyNode){
System.out.println("POINTER SET ON " + pointer);
IMyNode node = (IMyNode)pointer.getValue();
return node.someService().getName();
}
}
return "";
}
}编辑:这个问题是关于JXPath的。添加标记xpath而不是jxpath是错误的。
发布于 2012-11-18 00:09:59
尝试使用*而不是.。另外,我认为您可以使用标准的XPath函数local-name()而不是rules:getName()。
https://stackoverflow.com/questions/13435851
复制相似问题