Quantcast
Channel: htmlagilitypack Forum Rss Feed
Viewing all articles
Browse latest Browse all 655

New Post: Retrieve an attribute with XPath

$
0
0
I've got the following code snippet and would like to retrieve the value of an attribute by including it in the XPath expression:
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//a/@href"))
{
    HtmlAttribute attr = node as HtmlAttribute;
    if (attr != null)
    {
        return attr.Value;
    }
}
But the compiler complains it can never cast an HtmlNode to an HtmlAttribute. With XML, that should work just fine IIRC. How does it work with your Html* classes?

Viewing all articles
Browse latest Browse all 655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>