Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The easiest way to do that is to use XPath. Example to follow.</p> <pre><code> string xml = @"&lt;?xml version=""1.0"" encoding=""UTF-8""?&gt; &lt;rss version=""2.0""&gt; &lt;channel&gt; &lt;title&gt;Twitter public timeline&lt;/title&gt; &lt;link&gt;http://twitter.com/public_timeline&lt;/link&gt; &lt;description&gt;Twitter updates from everyone!&lt;/description&gt; &lt;language&gt;en-us&lt;/language&gt; &lt;ttl&gt;40&lt;/ttl&gt; &lt;item&gt; &lt;title&gt;yasu_kobayashi: rTwT: @junm : yayaya&lt;/title&gt; &lt;description&gt;yasu_kobayashi: rTwT: @junm : yayaya&lt;/description&gt; &lt;pubDate&gt;Tue, 28 Oct 2008 12:04:48 +0000&lt;/pubDate&gt; &lt;guid&gt;http://twitter.com/yasu_kobayashi/statuses/978829930&lt;/guid&gt; &lt;link&gt;http://twitter.com/yasu_kobayashi/statuses/978829930&lt;/link&gt; &lt;/item&gt;&lt;item&gt; &lt;title&gt;FreeGroup: WikiFortio - foobar http://tinyurl.com/5gvttf&lt;/title&gt; &lt;description&gt;FreeGroup: WikiFortio - foobar http://tinyurl.com/5gvttf&lt;/description&gt; &lt;pubDate&gt;Tue, 28 Oct 2008 12:04:47 +0000&lt;/pubDate&gt; &lt;guid&gt;http://twitter.com/FreeGroup/statuses/978829929&lt;/guid&gt; &lt;link&gt;http://twitter.com/FreeGroup/statuses/978829929&lt;/link&gt; &lt;/item&gt;&lt;/channel&gt;&lt;/rss&gt; "; XPathDocument doc = new XPathDocument(new StringReader(xml)); XPathNavigator nav = doc.CreateNavigator(); // Compile a standard XPath expression XPathExpression expr; expr = nav.Compile("/rss/channel/item"); XPathNodeIterator iterator = nav.Select(expr); // Iterate on the node set try { while (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); nav2.MoveToChild("title",""); Console.WriteLine(nav2.Value); nav2.MoveToParent(); nav2.MoveToChild("pubDate",""); Console.WriteLine(nav2.Value); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); </code></pre> <p>And this is jan's approach working</p> <pre><code> XmlDocument doc2 = new XmlDocument(); doc2.LoadXml(xml); XmlNode root = doc2.DocumentElement; foreach (XmlNode item in root.SelectNodes(@"/rss/channel/item")) { Console.WriteLine(item.SelectSingleNode("title").FirstChild.Value); Console.WriteLine(item.SelectSingleNode("pubDate").FirstChild.Value); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload