XML : Selecting a node if the attribute is equal to a predefined string

I'm currently using a loop which gives me a variable, which then needs to be fed into an Xpath method to get me any nodes with an attribute equal to my variable. So far, I've learned that Xpath allows you to select a node from the XML document using

  root.SelectNodes("Element[@Attribute='SpecificValue']")    

However, I'd like to know if there's a way I can insert a predefined variable where the specific value, so I can grab a different set of nodes with each iteration of my loop.

For example something like this:

  string  attribValue= "test"  root.SelectNodes("Element[@Attribute = attribValue]")    

No comments:

Post a Comment