XML Parsing with HtmlAgilityPack

azure-worker-roles c# html-agility-pack web-services xml

Question

I'm parsing xml with HtmlAgilityPack on WebService worker role, but there is something wrong. When I select childnode "link" get empty char. the xml like :

<link>
http://www.webtekno.com/google/google-ve-razer-dan-oyun-konsolu.html
</link>

my code for get link from rss is:

HtmlNodeCollection nodeList = doc.DocumentNode.SelectNodes("//item");
foreach (HtmlNode node in nodeList)
{
    string newsUri = node.ChildNodes["link"].InnerText;
}

I think gets empty char cause link node includes new line and after link. How can I get link in the node?

Accepted Answer

Put that line before loading HtmlDocument

HtmlNode.ElementsFlags["link"] = HtmlElementFlag.Closed;

That is all.

By default, its value is HtmlElementFlag.Empty and treated like meta and img tags...




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why