Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

This is what I am dealing with regarding the path to the nodes and trying to decipher what needs to be done. The bottom paths is what I got from using Chrome, as you can see after every /li[?] the number is different. How can I get all the values under the product_list even thought the li value changes?

Also, what if multiple values are listed under each node and I want to get them all ie.

part#,
price,
description
location


XML
<h3>
<a href="http://www.somesite.com/shop.html" title="Some description of the product">Product description</a>
</h3>


//*[@id="product_list"]/li[1]/div[2]/h3/a
//*[@id="product_list"]/li[2]/div[2]/h3/a
//*[@id="product_list"]/li[3]/div[2]/h3/a
//*[@id="product_list"]/li[4]/div[2]/h3/a
//*[@id="product_list"]/li[5]/div[2]/h3/a



Appreciate any help....
Posted

1 solution

Try removing the numbers after the li:
xpath
//*[@id="product_list"]/li/div[2]/h3/a

The number in square brackets indicates that you want to select the matching element at the specified index. By removing that restriction, you will select all matching elements.

The selector is an XPath[^] expression.
 
Share this answer
 
Comments
theadmin 14-May-15 18:11pm    
Thank you very much for that, I really need to brush up on this XPath stuff.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900