3

我尝试ends-with在以下模式下在 Html Agility Pack 中使用://span[ends-with(@id, 'Label2')]and //span[ends-with(., 'test')],但它不起作用。

所有其他功能,喜欢starts-with并且运行contains良好。

谁能帮我?

4

2 回答 2

4

可以找到一个hack!它是这样的:

//span['Label2'=substring(@id, string-length(@id)-string-length('_Label2')+1)]

于 2009-12-15T08:12:38.140 回答
3

是的; 它不受支持,无论是在此处还是在XmlDocument. 也许手动迭代//span[@id]

foreach (var node in from HtmlNode n in doc.DocumentNode.SelectNodes(@"//span[@id]")
                     where n.GetAttributeValue("id","").EndsWith("Label2")
                     select n)
 {
     Console.WriteLine(node.OuterHtml);
 }
于 2009-12-09T12:27:17.647 回答