Convert XPathNavigator to HtmlAgilityPack's HtmlNode
-
17-05-2021 - |
Question
It is possible to convert XPathNavigator
to HtmlNode
?
Here is the code:
public string ContentByName(string name)
{
if (name == null)
throw new ArgumentNullException("name");
XPathExpression expr = _CreateXPathExpression(String.Format("//meta[@name[Extensions:CaseInsensitiveComparison('{0}')]]", name));
XPathNodeIterator it = _headNav.Select(expr);
if (!it.MoveNext())
return null;
XPathNavigator node = it.Current;
// How should I transform XPathNavigator node to HtmlNode here?
}
Solution
'it.Current' in your example returns an instance of HtmlNodeNavigator
which has a CurrentNode
property which in turn returns the HtmlNode
.
For example
HtmlNodeNavigator nodeNavigator = it.Current as HtmlNodeNavigator;
HtmlNode node = nodeNavigator.CurrentNode;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow