一部のルート オブジェクトにはフィールドがありますMyCollection myCollection
。クラスはインターフェイスをMyCollection
実装しCollection
ます。要素の名前は呼び出すことで利用できるので、クラスsomeService().getName()
を作成しました。Rules
context.getValue("/myCollection");
myCollection を返します - OK
context.getValue("//myCollection");
myCollection を返します - OK
context.getValue("/myCollection/.[rules:getName() = 'secondName']");
「secondName」を返すIMyNode
インスタンスを
返します - OKsomeService().getName()
行
context.getValue("/myCollection//.[rules:getName() = 'secondName']");
の後、次の行は実行されません。また例外なく、寛大なモードは設定されていません。何が起こっているのかわかりません。クラスの 8 行目は、 をRules
印刷し"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に関するものです。jxpath の代わりに xpath タグを追加するのは間違っていました。