Reputation: 6305
I have a html structure like this..
<div id="divid">
<ul id="ulid">
<li style="margin-left: 8px">
<strong>books</strong>
</li>
<li style="margin-left: 6px">
<a hre="">
<span id="spanid">first line</span></a>
</li>
<li style="margin-left: 6px">
<a hre="">
<span id="spanid">2nd line</span></a>
</li>
</ul>
</div>
i am parsing this html part and using xpath query
$xpath->query('//div[@id="divid"]/ul[@id="ulid"]/li/a');
and the output i want is
first line
2nd line
as for as i understand, my xpath query is okay if "strong" tag was not present in first "li" tag.
the original code on which i was working was...
<ul data-typeid="n" id="ref_1000">
<li style="margin-left: -18px;">
<a href="/s/ref=sr_ex_n_0?rh=i%3Aaps%2Ck%3Ahow+to+grow+tomatoes&sort=salesrank&keywords=how+to+grow+tomatoes&ie=UTF8&qid=1327692925">‹ <span class="expand">Any Department</span></a>
</li>
<li style="margin-left: 8px;">
<strong>Books</strong>
</li>
<li style="margin-left: 6px;">
<a href="/s/ref=sr_nr_n_0?rh=k%3Ahow+to+grow+tomatoes%2Cn%3A283155%2Cp_n_feature_browse-bin%3A618073011%2Cn%3A%211000%2Cn%3A48&bbn=1000&sort=salesrank&keywords=how+to+grow+tomatoes&ie=UTF8&qid=1327692925&rnid=1000">
<span class="refinementLink">Crafts, Hobbies & Home</span><span class="narrowValue"> (19)</span>
</a>
</li>
<li style="margin-left: 6px;">
<a href="/s/ref=sr_nr_n_1?rh=k%3Ahow+to+grow+tomatoes%2Cn%3A283155%2Cp_n_feature_browse-bin%3A618073011%2Cn%3A%211000%2Cn%3A10&bbn=1000&sort=salesrank&keywords=how+to+grow+tomatoes&ie=UTF8&qid=1327692925&rnid=1000">
<span class="refinementLink">Health, Fitness & Dieting</span><span class="narrowValue"> (3)</span>
</a>
</li>
<li style="margin-left: 6px;">
<a href="/s/ref=sr_nr_n_2?rh=k%3Ahow+to+grow+tomatoes%2Cn%3A283155%2Cp_n_feature_browse-bin%3A618073011%2Cn%3A%211000%2Cn%3A6&bbn=1000&sort=salesrank&keywords=how+to+grow+tomatoes&ie=UTF8&qid=1327692925&rnid=1000">
<span class="refinementLink">Cookbooks, Food & Wine</span><span class="narrowValue"> (2)</span>
</a>
</li>
</ul>
and i want to extract
Crafts, Hobbies & Home etc closed in span tag
Upvotes: 0
Views: 1133
Reputation: 60414
Taking the provided expression at face value -- i.e. ignoring any contradictions between the expression and your description of it -- you can use the following expression to exclude li
elements that contain a strong
child:
//div[@id="divid"]/ul[@id="ulid"]/li[not(strong)]/a
Upvotes: 4