2

My program is a simple c# console application, I am unsure of howto achieve my goal, basically I am selecting a single node but I would like to ignore an tag with a particular text value, my code is below.

string name = item.SelectSingleNode("//select[contains(@id,'var')]//option")
                  .GetInnerTextFromNode();

I know in jQuery you could use :not filter, but not sure in C# and I have search for documentation for the pack, but nothing has surfaced.

Thank you

CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
user3091209
  • 81
  • 1
  • 5
  • 2
    You're looking for the `not()` operator. The syntax parsed by the HTML Agility Pack is actually XPath, so if you search for that you should find a lot more answers :) http://stackoverflow.com/questions/11024080/how-to-use-not-contains-in-xpath – CodingIntrigue Dec 11 '13 at 13:16
  • Thank you that work's a treat! – user3091209 Dec 11 '13 at 13:23

1 Answers1

3

Simply taking RGraham's comment and turning it into an answer:

 string name = item.SelectSingleNode("//select[not(contains(@id,'var'))]//option")
              .GetInnerTextFromNode();

As for guidance on what kind of functions you can use, check out the w3schools XPath tutorials.

Developer
  • 231
  • 4
  • 19
jessehouwing
  • 106,458
  • 22
  • 256
  • 341