I am having trouble finding good xQuery tutorials, basically what I am trying to do is retreive the text etc... from this html node
<div class="venue">
<div class="vitem">
<p style="padding: 6px 0pt 0pt;" class="label">ADDRESS:</p>
<p class="item-big">blabla</p>
</div><br class="clear">
<div class="vitem">
<p style="padding: 6px 0pt 0pt;" class="label">PHONE:</p>
<p class="item-big">123</p>
</div><br class="clear">
<div class="vitem">
<p style="padding: 6px 0pt 0pt;" class="label">WEB:</p>
<p class="item-big">etc...</p>
</div><br class="clear">
</div>
I'd like to know how can I get the data out of the 2nd p in the third div[@class="vitem"]
Or the p directly following the p[@class="label"] that contains the text WEB:
Edit: Answeres already helped a great bit, however my second question is if the layout changes to something like this
<div class="venue">
<div class="vitem">
<p style="padding: 6px 0pt 0pt;" class="label">ADDRESS:</p>
<p class="item-big">blabla</p>
</div><br class="clear">
<div class="vitem">
<p style="padding: 6px 0pt 0pt;" class="label">WEB:</p>
<p class="item-big">etc...</p>
</div><br class="clear">
</div>
How do i get the etc..., knowing only that it follows a p with the class label containing the text WEB:? it's no longer in div[3]/p[2]
Thanks!
I'd like to know how can I get the data out of the 2nd p in the third div[@class="vitem"]
Use:
/*/div[@class='vitem'][3]/p[2]/text()
This means: get all the text node children of the second p child of the third of all div elements that have an attribute class with value "vitem" and that are children of the top element.
Or the p directly following the p[@class="label"] with the data WEB:
Use:
/*/div[@class='vitem'][3]/p[@class='label']
/following-sibling::p[1]/text()
This means: get all the text node children of the first following-sibling p of any p element with class attribute with value "label", that is a child of the third of all div elements that have an attribute class with value "vitem" and that are children of the top element.
UPDATE: The OP has added a second question: he wants just to select the p that has as a string value the text "etc..."
Use:
/*/div/p[.='etc...']
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