tags:

views:

48

answers:

1

Hi, this is for school, if you know your XPath and wouldn't mind telling me if I'm correct:

1. //a[/b]/a

every 'a' that has a parent 'a' in a tree where the root is 'b'. (the location of the [/b] is irrelevant? i.e. is the above equivalent to //a/a[/b] ?

2. //*[//a]//a[/a][a]

breaking it down from left to right: //*[//a] means all elements having a descendant 'a', therefore //*[//a]//a (quite school-excerisely) means all 'a' elements. and //*[//a]//a[/a] means all 'a' elements in a tree where the root is 'a', and finally - //*[//a]//a[/a][a] means all 'a' elements in a tree where the root is 'a' that have a child 'a'.

Thanks for any help, can't seem to get a straight answer anywhere.

+1  A: 

What class is quizzing you on arcane XPath queries? Wow.

  1. //a[/b]/a
    Yes, you have that right. The location of [/b] is irrelevant.

  2. //*[//a]//a[/a][a]
    Technically //*[//a]//a is equivalent to //*//a which means all 'a' elements which have an ancestor element. So if the root element is 'a' it won't won't match. Aside from that, yes, your analysis is correct.

For what it's worth, a few years ago I implemented a full XPath parser from scratch in JavaScript for a project I worked on. So I really hope my answers are right!

John Kugelman
Thanks (I put in a comment above).It's a silly class about Search Engines where they cover too much at too shallow of a level :)
bloodcell