The problem is that your
<P>
tag isn't closed, so HAP is treating the
<strong>
tag as a
sibling element, not a
child element.
The solution is buried in the discussions on the CodePlex site:
Now, you can tweak the HTML agility pack to better suit what you expect using the HtmlNode.ElementFlags static property ... What you can do is tell it you don't want to support unclosed <p>
tags:
HtmlNode.ElementsFlags.Remove("p");
HtmlDocument doc = new HtmlDocument();
doc.Load(...);
You're also missing quotes around the attribute value, and you should only use a single
/
for the descendant node:
HtmlNode.ElementsFlags.Remove("p");
HtmlDocument html = new HtmlDocument();
html.LoadHtml(data);
var nodes = html.DocumentNode.SelectNodes("//p[@align='justify']/strong[1]");
return nodes == null ? null : nodes.Select(n => n.InnerHtml).FirstOrDefault();