2

私のXML構造は

<root>
  <elem1>..</elem1>
  <elem1>..</elem1>
  *<elem1>..</elem1>*
  <elem2>
    <elem1>..</elem1>
    <elem1>..</elem1>
    ¬ <elem1>..</elem1> ¬
  </elem2>
</root>

root の直下の子 (* * でマーク) の最後の elem1 を選択する必要があります。

QueryPath - http://querypath.orgでそれを行いたいです。しかし、JQuery 構文も役に立ちます。

$root->find('elem1')->last();
$root->find('elem1:last);
$root->find('elem1:last-child); 

上記の 3 つすべてで、¬ でマークされた elem1 が選択されます

4

3 に答える 3

2

last次の方法を使用できます。

$('root > elem1').last();

QueryPath APIを見ると、次のようにコーディングできるようです。

$root->children('elem1')->last()
于 2013-02-16T19:25:08.963 に答える
0

これは動作します

$root->find('elem1:last-of-type'); 

概念実証を提供してくれたDavidThomasに感謝します http://jsfiddle.net/davidThomas/RehZ7/

于 2013-02-16T19:37:23.313 に答える
0

一致した要素のセットをセット内の最後の要素に減らすlast()メソッドは、以下のようにそれを行うことができます。

$('root > elem1').last();

また

親の最後の子であるすべての要素を選択する:last-childSelectorを使用できます。

$('root elem1:last-child');
于 2013-02-16T19:27:49.113 に答える