I want to select a node based on an attribute value. I am using C# program to derive on the attribute value which is stored in a variable. The below code returns null. How can I compare the attribute value against a variable?

     string posSecond = "test";
     SelectSingleNode("//viewentries/viewentry[@position=posSecond]");

Thanks!

Recommended Answers

SelectSingleNode(string.Format("//viewentries/viewentry[@position='{0}']", posSecond));

should work, assuming the position attribute contains a string value.

Jump to Post

All 2 Replies

SelectSingleNode(string.Format("//viewentries/viewentry[@position='{0}']", posSecond));

should work, assuming the position attribute contains a string value.

Spot on! Yes, the variable is defined as string.
Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.