可以将XPathNavigator
转换为HtmlNode
吗?
这是代码:
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?
}
答案 0 :(得分:1)
'it.Current'返回HtmlNodeNavigator
的实例,该实例具有CurrentNode
属性,该属性又返回HtmlNode
。
例如
HtmlNodeNavigator nodeNavigator = it.Current as HtmlNodeNavigator;
HtmlNode node = nodeNavigator.CurrentNode;