I'm trying to create a WPF treeview based on the output from an xpath query. The idea is that, based on a search string, a treeview representing a tiny subset of a very large xml document will be presented. WPF and xpath are totally new to me (couple of weeks) so possibly a dumb question...
In a console application, this works fine and gives exactly what I want as a basis for the tree.
XmlNodeList nodeList = root.SelectNodes("//item[not (item) and contains(name, 'kidney')]//ancestor::item");
foreach (XmlNode node in nodeList)
{
file.WriteLine($"{node.ChildNodes[0].InnerText}");
//Console.WriteLine($"{node.Name} - {node.InnerText}");
}
However, when I use the same xpath in a binding as follows:
ItemsSource="{Binding Source={StaticResource xmlDataProvider}, XPath=//item[not (item) and contains(name, 'kidney')]//ancestor::item}"
I get a bunch or errors around the construction of the xpath piece (xpath = /* works fine). I thought it might be the single quotes but replacing with the XML special character or escaping with \ makes no difference. At this stage I'm wondering if nested xpath statements can be used at all?