ruby - XPath to select between two HTML comments is not working? -
i'm trying select content between 2 html comments, having trouble getting right (as seen in "xpath select between 2 html comments?"). there seems problem when new comments on same line.
my html:
<html> ........ <!-- begin content --> <div>some text</div> <div> <p>some more elements</p> </div> <!-- end content --><!-- begin content --> <div>more text</div> <!-- end content --> ....... </html> i use:
doc.xpath("//node()[preceding-sibling::comment()[. = ' begin content ']] [following-sibling::comment()[. = ' end content ']]") result:
<div>some text</div> <div> <p>some more elements</p> </div> <!-- end content --><!-- begin content --> <div>more text</div> what i'm trying get:
<div>some text</div> <div> <p>some more elements</p> </div>
if interested in first pair of comments, start looking first comment:
//comment()[.=' begin content ']/following::*[not(preceding::comment()[.=' end content '])] i.e.:
//comment()[1][.=' begin content '] <-- first suitable comment /following::* <-- take following nodes [not(preceding::comment()[.=' end content '])] <-- satisfying condition there no preceding "end comment"
Comments
Post a Comment