Html Agility Pack ends - doesn’t work

I tried using ends-withthe Html Agility Pack in the following mode: //span[ends-with(@id, 'Label2')]and //span[ends-with(., 'test')], but it does not work.

All other functions, such as starts-withand contains, work well.

Can anybody help me?

+3
source share
2 answers

There you can find a hack! This is something like this:

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

+4
source

Yes; it is not supported, neither here nor in XmlDocument. Perhaps repeat the operation manually over //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);
 }
+3
source

Source: https://habr.com/ru/post/1725152/


All Articles