求解。。。linq to xml

O湛狼O 2011-07-03 04:23:15
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <results>
- <songList>
- <!-- freemusic/song/result/Sb230d4b83cf4d4a9
-->
- <song>
<id>Sb230d4b83cf4d4a9</id>
<name>You Belong With Me</name>
<artist>泰勒 史薇芙特(Taylor Swift)</artist>
<artistId>Ac097678888daa741</artistId>
<album>Fearless - International Edition</album>
<duration>232.0</duration>
<canBeDownloaded>true</canBeDownloaded>
<hasFullLyrics>true</hasFullLyrics>
<canBeStreamed>true</canBeStreamed>
<albumId>B1367683ceabfe43b</albumId>
<hasSimilarSongs>false</hasSimilarSongs>
<hasRecommendation>false</hasRecommendation>
</song>
- <!-- freemusic/song/result/S1dcbc954d664eb88
-->
- <song>
<id>S1dcbc954d664eb88</id>
<name>Love Story</name>
<artist>泰勒 史薇芙特(Taylor Swift)</artist>
<artistId>Ac097678888daa741</artistId>
<album>Now That's What I Call Music 30</album>
<duration>233.0</duration>
<canBeDownloaded>true</canBeDownloaded>
<hasFullLyrics>true</hasFullLyrics>
<canBeStreamed>true</canBeStreamed>
<albumId>B5a5f1e0b80e94813</albumId>
<hasSimilarSongs>true</hasSimilarSongs>
<hasRecommendation>false</hasRecommendation>
</song>
</songList>
<estimatedResultCount>55</estimatedResultCount>
</results>

上面这个xml,我用var songs = from song in XElement.Load(@"http://www.google.cn/music/search?q=taylor%20swift&oq=taylor&aq=0&num=2&output=xml").Elements("song")
select song;

这个语句为什么读不了呢?
求大牛指教,然后又换了
XDocument songList = XDocument.Load(@"http://www.google.cn/music/search?q=taylor%20swift&oq=taylor&aq=0&num=20&output=xml");

var songs = from song in songList.Descendants("song")
select song;
这样还是读取不了,最后获取的结果都是0.请问是哪里错了呢?
...全文
75 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
O湛狼O 2011-07-03
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 q107770540 的回复:]

C# code

void Main()
{
var xml=XElement.Load(@"http://www.google.cn/music/search?q=taylor%20swift&oq=taylor&aq=0&num=2&output=xml");
var query=from x in xml.Descendants("song……
[/Quote]
好的,谢谢了
q107770540 2011-07-03
  • 打赏
  • 举报
回复

void Main()
{
var xml=XElement.Load(@"http://www.google.cn/music/search?q=taylor%20swift&oq=taylor&aq=0&num=2&output=xml");
var query=from x in xml.Descendants("song")
select new {
id= x.Element("id").Value,
name= x.Element("name").Value,
artist= x.Element("artist").Value
//剩下的自己加吧 这样测试是可以读取到数据的
};
Console.WriteLine(query);
}

暖枫无敌 2011-07-03
  • 打赏
  • 举报
回复


XElement songList = XElement .Load(@"http://www.google.cn/music/search?q=taylor%20swift&oq=taylor&aq=0&num=20&output=xml");

var songs = from song in songList.Descendants("song")
select song;
暖枫无敌 2011-07-03
  • 打赏
  • 举报
回复

XDocument songList = XDocument.Load(@"http://www.google.cn/music/search?q=taylor%20swift&oq=taylor&aq=0&num=20&output=xml");

var songs = from song in songList.Descendants("song")
select new {
id= xmlLog.Element("id").Value,
name= xmlLog.Element("name").Value,
artist= xmlLog.Element("artist").Value
};

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧