lucavilla
asked on
What's the XPath for this example?
What's the XPath for grabbing a "<DIV id="myid">...</div>" piece of an html page and only if there are 2 to 5 nested DIVs?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
mmh, then it gets tricky
you could test for
//DIV[@id = 'myid'][DIV/DIV| DIV/DIV/DIV| DIV/DIV/DIV/DIV| DIV/DIV/DIV/DIV/DIV ]
bit clumsy, I know, I hope you don't have to do this for 2 to 40 :-)
the other way is to go as deep as possible and look up (that is the only ay to cound a single path), but that only works as a replaement for the third situation
you could test for
//DIV[@id = 'myid'][DIV/DIV| DIV/DIV/DIV| DIV/DIV/DIV/DIV| DIV/DIV/DIV/DIV/DIV ]
bit clumsy, I know, I hope you don't have to do this for 2 to 40 :-)
the other way is to go as deep as possible and look up (that is the only ay to cound a single path), but that only works as a replaement for the third situation
ASKER
Wow thanks it works, you're a genius! and thanks to you I'm starting to love this (still unknown to me) XPATH, I start to read a tutorial to learn it!
welcome
ASKER
Only a problem because I was not clear in my question. How can I adapt your second solution to count only the *levels* of sub-DIVs?
Example:
<div>abc
<div>def
</div>ghi
<div>lmn
</div>opq
</div>
Your solution counts 2 descendant DIVs.
How can I tell you count only the sub-levels of DIVs, i.e. 1?