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.
What class is quizzing you on arcane XPath queries? Wow.
//a[/b]/a
Yes, you have that right. The location of [/b]
is irrelevant.
//*[//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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With