2

My XML Structure is like

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

I need to select the last elem1 of the immediate child of root (marked with * *).

I want to do it in QueryPath - http://querypath.org. But JQuery syntaxes could also help.

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

All the above three selects the elem1 marked with ¬

Brighton Vino
  • 295
  • 3
  • 10

3 Answers3

2

You can use last method:

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

By looking at QueryPath API it seems you can code:

$root->children('elem1')->last()
Ram
  • 143,282
  • 16
  • 168
  • 197
0

last() method that reduces the set of matched elements to the final one in the set, can do it for you like below;

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

OR

You can use :last-child Selector that selects all elements that are the last child of their parent.

$('root elem1:last-child');
Bhushan Firake
  • 9,338
  • 5
  • 44
  • 79
0

This works

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

Thanks David Thomas for Proof of Concept http://jsfiddle.net/davidThomas/RehZ7/

Brighton Vino
  • 295
  • 3
  • 10