0

I've got a ListBox with an XMLDataProvider that I want to filter on the specific value of a node.

I've tried the following but it returns the full <ITEMS> again.

<XmlDataProvider x:Key="ItemDataSource" XPath="./ITEMS[ITEM[./PROPERTY='value']]" Source="data.xml">
</XmlDataProvider>

This is the XML file:

<ITEMS>
  <ITEM>
    <PROPERTY>value</PROPERTY>
  </ITEM>
  <ITEM>
    <PROPERTY>other value</PROPERTY>
  </ITEM>
</ITEMS>

./ITEMS/ITEM[./PROPERTY/text()='value'] works but since it isn't wrapped by <ITEMS> it refuses to display the data.

  • What output you expect? `ITEMS`, `ITEM`... what exactly? Also note that `./ITEMS/ITEMS[./PROPERTY/text()='value']` won't work as `ITEMS` has no child `ITEMS`... Do you mean `./ITEMS/ITEM[./PROPERTY/text()='value']`? – Andersson Feb 23 '17 at 10:42
  • Sorry, just saw my mistake there and edited it – Maartje Eyskens Feb 23 '17 at 10:44
  • I expect with only the matched my search, or any way to put only those in a ListBox – Maartje Eyskens Feb 23 '17 at 10:45
  • Oh...AFAIK you cannot do this with `XPath` as it can only return element with **all** descendants without modifications – Andersson Feb 23 '17 at 10:52

1 Answers1

0

I've found the solution using ./ITEMS/ITEM[./PROPERTY/text()='value'] I needed to unset the XPath in ItemsSource.