views:

124

answers:

2

Hi everyone!

I tried to use ends-with in 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, like starts-with and contains works well.

Can anyone help me?

Tanks in advance!

+3  A: 

Yes; it isn't supported, neither here nor in XmlDocument. Perhaps iterate 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);
 }
Marc Gravell
I thinks I'll have to implement a hard-coded solution, like one you propose, if none is recommending any other 'patch'.
mxg
+2  A: 

There can be found a hack! It is something like this:

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

mxg