title: process xmlnodeslist programatically in c# instead of XAML
body: <p>Context: XAML, WPF, C#.</p>
  
  <p>There is some XML data. (see below).</p>
  
  <p>There is a ListBox that should display the InnerText of  subNodes of  nodes 
   (because there are others same level as  node with  as subnode)</p>
  
  <p>I obtained XmlNodesList with news= "getTagsbyname("item");</p>
  
  <p>I've set the ItemsSource for the Listbox to news</p>
  
  <p>But I want displayed ONLY the title, not all the data inside the </p>
  
  <p>So I've tried with DisplayMemberPath= "title";</p>
  
  <p>Unfortunately this is not working, because there is no "news.title" property. Instead the data needed is in news.ChildNodes[0].InnerText</p>
  
  <p>So I've tried with DisplayMemberPath = "ChildNodes[0].InnerText". Obviously, this in not working either.</p>
  
  <pre><code>XmlDocument rss = new XmlDocument();
  rss.Load("c:\rss.xml");
  XmlElement rc = rss.DocumentElement;
  XmlNodeList news = rc.GetElementsByTagName("item");
  listbox1.ItemsSource = news;
  listbox1.DisplayMemberPath = "ChildNodes[0].InnerText";
  </code></pre>
  
  <p>Because I didn't know how to solve this, I've switched to XAML and solved the issue with XmlDataProvider, DataTemplate and Xpath:</p>
  
  <pre><code>&lt;XmlDataProvider x:Key="titles"   Source="C:\rss.xml"  XPath="/rss/channel/item" /&gt;
   &lt;ListBox Name="listbox1" SelectionChanged="listbox1_SelectionChanged" ItemsSource="        {Binding Source={StaticResource titles}}" &gt;
  &lt;ListBox.ItemTemplate&gt;
  &lt;DataTemplate&gt;
  &lt;TextBlock Text="{Binding XPath=title}"/&gt;
  &lt;/DataTemplate&gt;
  &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>My question is: </p>
  
  <p>How to accomplish the same thing in C#, not in XAML ?</p>
  
  <p>Because I want the rss link to be specified in a textBox (by user) like rss.Load (textBox1.Text) instead of saving the .xml file locally first.</p>
  
  <p>My problem is the "news" is a List and the data is not a property or attribute but a property of a member i.e. news.ChildNodes[0].InnerText.  And the syntax accessing this - I dont know how to pass it in a string for ItemsSource or DisplayMemberPath.</p>
  
  <p>I hope I was clear and specific describing my problem.</p>
  
  <p>Thanks in advance for your valuable suggestions.</p>
  
  <p>Here is the XML model.</p>
  
  <pre><code>&lt;rss&gt;
  &lt;channel&gt;
  &lt;author&gt;
  &lt;title&gt;qwer&lt;/title&gt;
  &lt;image/&gt;
  &lt;link&gt;www&lt;/link&gt;
  &lt;/author&gt;
  &lt;item&gt;
  &lt;title&gt;header1&lt;/title&gt;
  &lt;description&gt;abcd&lt;/description&gt;
  &lt;category&gt;1&lt;/category&gt;
  &lt;/item&gt;
  &lt;item&gt;
  &lt;title&gt;header2&lt;/title&gt;
  &lt;description&gt;efgh&lt;/description&gt;
  &lt;category&gt;2&lt;/category&gt;
  &lt;/item&gt;
  &lt;/channel&gt;
  &lt;/rss&gt;
  </code></pre>