The example on codeplex is this :
HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
{
HtmlAttribute att = link["href"];
att.Value = FixLink(att);
}
doc.Save("file.htm");
The first issue is HtmlDocument.DocumentElement does not exist! What does exist is HtmlDocument.DocumentNode but even when I use that instead, I'm unable to access the href attribute as described. I get the following error:
Cannot apply indexing with [] to an expression of type 'HtmlAgilityPack.HtmlNode'
Here's the code I'm trying to compile when I get this error:
private static void ChangeUrls(ref HtmlDocument doc)
{
foreach(HtmlNode link in doc.DocumentNode.SelectNodes("//@href"))
{
HtmlAttribute attr = link["href"];
attr.Value = Rewriter(attr.Value);
}
}
UPDATE: I Just found that the example was never meant to work...And I've got a solution after reading the example code...I'll post my solution for other people like me to enjoy once completed.