0

So I m using Htmlagilitypack on server side to parse html in C#. Here's a Question.. i have 2 div elements

<div>
<a data-clear="movies-something"></a>
<p data-clear="movies-something"></p>
</div>

<div>
<a data-clear="music-something"></a>
<p data-clear="music-something"></p>
</div>

i am looping through the div elements and want to find specific data-clear attributes for that. problem is when i am selecting nodes using

var cols = fdm.SelectNodes("//@data-clear");

on second case i am finding 4 instead of 2 columns..

how to select within only currently looping through div

Vishal Sharma
  • 2,773
  • 2
  • 24
  • 36
  • its not duplicate i want my list within specific tags – Vishal Sharma Aug 30 '13 at 14:12
  • It is a duplicate. XPATH expression that return attribute nodes are not supported (because Html Agility Pack simple does not define an attribute as being a node, unlike the XML equivalent) – Simon Mourier Aug 30 '13 at 14:31
  • so duplicate link has question like : I'm trying to retrieve a specific image from a html document, my question is : i don't want specific images i want things from perticular section in this case Div.. – Vishal Sharma Aug 31 '13 at 08:23

1 Answers1

0

Change your XPATH expression on follows

var cols = fdm.SelectNodes("//div[1]//@data-clear");
MikkaRin
  • 3,026
  • 19
  • 34
  • You're 100% right for XPATH in general, but the Html Agility Pack XPATH implementation doesn't support selecting on attributes. Check the links in my comment. – Simon Mourier Aug 30 '13 at 09:25
  • It was in 2009. Now HtmlAgilityPack supports selection by attributes. http://htmlagilitypack.codeplex.com/wikipage?title=Examples – MikkaRin Aug 30 '13 at 09:31
  • Nope. You're confusing this kind of expression `/element[@att]` with this `/@att`. The latter was never supported. – Simon Mourier Aug 30 '13 at 09:42
  • assume this is true but can we do something like this fdm.SelectNodes("//div["+index+"]//@data-clear"); or can we?? – Vishal Sharma Aug 30 '13 at 14:10
  • Please read the possible duplicate. This XPATH expression is *not possible* with Html Agility Pack. – Simon Mourier Aug 30 '13 at 14:29