0

I have a rss feed which is below format.

<response>
  <results>
  <game>
     <image>
       <icon_url>
          <![CDATA[
             http://-------------------
            ]]>
       </icon_url>
       <medium_url>
         <![CDATA[
           http://----
          ]]>
       </medium_url>
      </image>
   </game>
 </results>
</response>

Now, I want to retrieve the medium_url using LINQ.

var items = from item in rssFeed.
            Elements("response").Elements("results").Elements("game")
            select new
            {
                Image1 = item.Element("image").Element("medium_url").value
            }

This doesn't seem to work.

4

1 回答 1

0

You just need to make a small change:

var items = from item in rssFeed.
            Elements("response").Elements("results").Elements("game")
            select new
            {
                Image1 = (string)item.Element("image").Element("medium_url")
            };

or

var items = from item in rssFeed.
            Elements("response").Elements("results").Elements("game")
            select new
            {
                Image1 = item.Element("image").Element("medium_url").Value
            };
于 2013-03-30T22:05:53.683 回答