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

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.