0

如果节点具有特定属性,是否可以选择节点?我需要的节点都有一个“data-rel”属性。我只想选择具有该属性的节点,而不考虑“data-rel”属性值。

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

我试过了 ...

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

……无济于事。

4

1 回答 1

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
于 2013-07-20T13:40:07.860 回答