Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy isn't this LINQ to XML Query Working (Amazon S3)
    text
    copied!<p>Given this XML ...</p> <pre><code>&lt;ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"&gt; &lt;Name&gt;public.rpmware.com&lt;/Name&gt; &lt;Prefix&gt;&lt;/Prefix&gt; &lt;Marker&gt;&lt;/Marker&gt; &lt;MaxKeys&gt;1000&lt;/MaxKeys&gt; &lt;IsTruncated&gt;false&lt;/IsTruncated&gt; &lt;Contents&gt; &lt;Key&gt;0.dir&lt;/Key&gt; &lt;LastModified&gt;2008-06-25T16:09:49.000Z&lt;/LastModified&gt; &lt;ETag&gt;"0ba2a466f9dfe225d7ae85277a99a976"&lt;/ETag&gt; &lt;Size&gt;16&lt;/Size&gt; &lt;Owner&gt; &lt;ID&gt;1234&lt;/ID&gt; &lt;DisplayName&gt;kyle&lt;/DisplayName&gt; &lt;/Owner&gt; &lt;StorageClass&gt;STANDARD&lt;/StorageClass&gt; &lt;/Contents&gt; &lt;!-- repeat similar 100x --&gt; &lt;/ListBucketResult&gt; </code></pre> <p>And this C# code:</p> <pre><code>XDocument doc = XDocument.Load(xmlReader); var contents = from content in doc.Descendants("Contents") select new {Key = content.Element("Key").Value, ETag = content.Element("ETag").Value}; foreach (var content in contents) { Console.WriteLine(content.Key); Console.WriteLine(content.ETag); } </code></pre> <p>I know the Xdoc is not empty and contains the right XML.</p> <p>I also implemented some ScottGu code (<a href="http://weblogs.asp.net/scottgu/archive/2007/08/07/using-linq-to-xml-and-how-to-build-a-custom-rss-feed-reader-with-it.aspx" rel="noreferrer">http://weblogs.asp.net/scottgu/archive/2007/08/07/using-linq-to-xml-and-how-to-build-a-custom-rss-feed-reader-with-it.aspx</a>) as a sanity check and it works exactly as expected.</p> <pre><code>XDocument doc2 = XDocument.Load(@"http://weblogs.asp.net/scottgu/rss.aspx"); var posts = from items in doc2.Descendants("item") select new { Title = items.Element("title").Value }; foreach (var post in posts) { Console.WriteLine(post.Title); } </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