SelectSingleNode based on value of tag

432 Views Asked by At

This code works:

XmlNode Key = Site.SelectSingleNode(PathString, manager);

But what I really want is essentially:

string desiredValue="Ribeye";
XmlNode Key = Site.SelectSingleNode(PathString[Value=desiredValue], manager);

desiredValue is NOT an attribute, and the string variable will be changing between uses. So if my tag was FavoriteSteak, the XML line would be:

<FavoriteSteak>Ribeye</FavoriteSteak>

...and I want the SelectSingleNode call to return an instance of FavoriteSteak that equaled "Ribeye".

How do I write the filter?

1

There are 1 best solutions below

0
On

Thanks to @Andersson for the inspiration. The resulting code looks like:

                var FilterString = String.Format("[text()='{0}']", desiredValue);

            XmlNode Key = Site.SelectSingleNode(KeyPath+FilterString, manager);