Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XPath-选择具有属性的节点_C#_Xpath - Fatal编程技术网

C# XPath-选择具有属性的节点

C# XPath-选择具有属性的节点,c#,xpath,C#,Xpath,如果节点具有特定属性,是否可以选择节点?我需要的节点都有一个“datarel”属性。我只想选择具有该属性的节点,而不考虑“data rel”属性值 <a href="/someurl.php" data-rel="..."> 我试过 List<HtmlAgilityPack.HtmlNode> groups = doc.DocumentNode.SelectNodes("//a[contains(@data-rel)]").Distinct().ToList();

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

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

我试过

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

。。。没用。

试试
//a[@data rel]

参考文献


有趣的是,contains()的规范中是否有任何东西误导您认为这就是函数所做的,或者您只是在猜测?作为规范的现任编辑,我很想知道为什么人们会犯如此严重的错误。
//title[@lang]  Selects all the title elements that have an attribute named lang
employee[@secretary and @assistant] selects all the employee children of the context node that have both a secretary attribute and an assistant attribute