I am writing a C# program where I would like to store a series of XPath statements as strings and evaluate them against an XMLDocument (or some other C# XML structure if there's a better one for this purpose) and store the resulting values in a dictionary / object.
My challenge is that my XPaths are not being able to be evaluated.
As a very simplified example, suppose this is my XML:
<child1 Id="Id1" Name="Name1" />
<child2 Id="Id2" Name="Name2" />
var xpath = @"//a/*[@Id='Id1']/name()";
var xml = @"<root><a><child1 Id='Id1' Name='Name1' /><child2 Id='Id2' Name='Name2' /></a></root>";
var doc = new XmlDocument();
var navigator = doc.CreateNavigator();
string ChildName = (string)navigator.Evaluate(xpath);
Pretty sure you just need to rearrange your XPath if I'm understanding you correctly. Try this: