XPath - 选择具有属性的节点

时间:2013-07-20 13:31:24

标签: c# xpath

如果它们具有某个属性,是否可以选择节点?我需要的节点都有“data-rel”属性。我想只选择具有该属性的节点,而不管“data-rel”属性值。

<a href="/someurl.php" data-rel="...">

我试过......

List<HtmlAgilityPack.HtmlNode> groups = doc.DocumentNode.SelectNodes("//a[contains(@data-rel)]").Distinct().ToList();

......无济于事。

1 个答案:

答案 0 :(得分:2)

尝试//a[@data-rel]

请参阅http://www.w3schools.com/xpath/xpath_syntax.asp

//title[@lang]  Selects all the title elements that have an attribute named lang

参考http://www.w3.org/TR/xpath/#path-abbrev

employee[@secretary and @assistant] selects all the employee children of the context node that have both a secretary attribute and an assistant attribute