XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("voteList",
new XAttribute("PageSize", PageSize),
new XAttribute("TotalPages", TotalPageNum),
new XAttribute("Count", TotalNum),
new XAttribute("CurrentPage", CurrentPage),
from d in alldata
select (new XElement(
"vote",
new XElement("id", d.userID),
new XElement("name", d.userRealName),
new XElement("userImg", d.userImg),
new XElement("company", d.userCompany),
new XElement("leaveword", d.userLeaveWord),
new XElement("voteCounts", d.voteCount),
new XElement("img1url", d.caseS5_1),
new XElement("img2url", d.caseS5_2)
))));
context.Response.Write(doc);
context.Response.End();

//---------------------------------------------------

var client = new RestClient
{
BaseUrl = "http://api.douban.com/music/subjects"
};
var request = new RestRequest(Method.GET);
request.AddHeader("User-Agent", Guid.NewGuid().ToString());
request.AddParameter("q", keyWord);
request.AddParameter("start-index", 1);
request.AddParameter("max-results", 20);
request.AddParameter("apikey", "0e63b1707b5f4ccd2b2b1451721de667");
client.ExecuteAsync(request, (response) =>
{
this.MusicList = new ObservableCollection<Music>();
var resource = response.Content;
XElement xmlMusic = XElement.Parse(resource);
var entryCollection = (from f in xmlMusic.Descendants() where f.Name.LocalName == "entry" select f).ToList();
foreach (var entryElement in entryCollection)
{
Music music = new Music();
music.ID = (from f in entryElement.Descendants() where f.Name.LocalName == "id" select f).FirstOrDefault().Value;
music.Title = (from f in entryElement.Descendants() where f.Name.LocalName == "title" select f).FirstOrDefault().Value;
music.Image = new Uri((from f in entryElement.Descendants() where f.Name.LocalName == "link" && f.Attribute("rel").Value == "image" select f.Attribute("href").Value).FirstOrDefault());
music.Pubdate = (from f in entryElement.Descendants() where f.Name.LocalName == "attribute" && f.Attribute("name").Value == "pubdate" select f.Value).FirstOrDefault();
music.Singer = (from f in entryElement.Descendants() where f.Name.LocalName == "attribute" && f.Attribute("name").Value == "singer" select f.Value).FirstOrDefault();
music.Publisher = (from f in entryElement.Descendants() where f.Name.LocalName == "attribute" && f.Attribute("name").Value == "publisher" select f.Value).FirstOrDefault();

MusicRating rating = new MusicRating();
rating.Averate = float.Parse((from f in entryElement.Descendants() where f.Name.LocalName == "rating" select f.Attribute("average").Value).FirstOrDefault());
rating.Max = Int32.Parse((from f in entryElement.Descendants() where f.Name.LocalName == "rating" select f.Attribute("max").Value).FirstOrDefault());
rating.Min = Int32.Parse((from f in entryElement.Descendants() where f.Name.LocalName == "rating" select f.Attribute("min").Value).FirstOrDefault());
rating.NumRaters = Int32.Parse((from f in entryElement.Descendants() where f.Name.LocalName == "rating" select f.Attribute("numRaters").Value).FirstOrDefault());
music.Rating = rating;
this.MusicList.Add(music);
}
this.IsBusy = false;
var url=this.MusicList[0].ID;
this.CreateMusicDeatail(url);
});

C# linq to xml的更多相关文章

  1. LINQ系列:LINQ to XML类

    LINQ to XML由System.Xml.Linq namespace实现,该namespace包含处理XML时用到的所有类.在使用LINQ to XML时需要添加System.Xml.Linq. ...

  2. LINQ系列:LINQ to XML操作

    LINQ to XML操作XML文件的方法,如创建XML文件.添加新的元素到XML文件中.修改XML文件中的元素.删除XML文件中的元素等. 1. 创建XML文件 string xmlFilePath ...

  3. LINQ系列:LINQ to XML查询

    1. 读取XML文件 XDocument和XElement类都提供了导入XML文件的Load()方法,可以读取XML文件的内容,并转换为XDocument或XElement类的实例. 示例XML文件: ...

  4. Linq to Xml读取复杂xml(带命名空间)

    前言:xml的操作方式有多种,但要论使用频繁程度,博主用得最多的还是Linq to xml的方式,觉得它使用起来很方便,就用那么几个方法就能完成简单xml的读写.之前做的一个项目有一个很变态的需求:C ...

  5. [原创]Linq to xml增删改查Linq 入门篇:分分钟带你遨游Linq to xml的世界

    本文原始作者博客 http://www.cnblogs.com/toutou Linq 入门篇(一):分分钟带你遨游linq to xml的世界 本文原创来自博客园 请叫我头头哥的博客, 请尊重版权, ...

  6. c#操作xml文件(XmlDocument,XmlTextReader,Linq To Xml)

    主界面

  7. Linq对XML的简单操作

    前两章介绍了关于Linq创建.解析SOAP格式的XML,在实际运用中,可能会对xml进行一些其它的操作,比如基础的增删该查,而操作对象首先需要获取对象,针对于DOM操作来说,Linq确实方便了不少,如 ...

  8. LINQ to XML 编程基础

    1.LINQ to XML类 以下的代码演示了如何使用LINQ to XML来快速创建一个xml: 隐藏行号 复制代码 ?创建 XML public static void CreateDocumen ...

  9. XML基础学习02<linq to xml>

    Linq to XML的理解 1:这是一种比较好的操作Xml的工具. àXDocument 文档 àXElement 元素 àXAttribute 属性 àXText 文本 2:这里还是和我们之前创建 ...

  10. C# ~ 从 XML 到 Linq 到 Linq to XML

    .XML 可扩展标记语言 (Extensible Markup Language), 标记 (markup) 是关键部分,是标准通用标记语言 (Standard Generalized Markup ...

随机推荐

  1. mfc窗口,父窗口parentwindow,所有者窗口ownerwindow 区别

    一. parent:创建者,owner:所有者 小玉的父母生下小玉,养到8岁,卖给贾府当丫头小玉的父母是parent,贾府是owner 二. 1.Pop-up窗口: 一个弹出窗口是必须具有WS_POP ...

  2. HTML标签实现图片滚动显示

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  3. codeforces gym 100463I Yawner

    //这题挂得让我怀疑我最近是不是做了什么坏事 题意:一个人有两个集合,先在其中一个集合选一个数x,然后向右走x布,然后再在另一个集合里选一个数y,向左走y步,问是否能走完数轴上所有点. 解:显然是求g ...

  4. 【BZOJ 1088 扫雷Mine】模拟

    http://www.lydsy.com/JudgeOnline/problem.php?id=1088 2*N的扫雷棋盘,第二列的值a[i]记录第 i 个格子和它8连通的格子里面雷的数目. 第一列的 ...

  5. OpenStack securityGroup rule Set

    OpenStack DBaas 云数据即服务之☞troveError

  6. MS SQL 当记录不存在时插入insert INTO not exists

    INSERT INTO dbo.[T_DabaoTemp]  ([PType]           ,[pID]           ,[NewVersion]           ,[ParentC ...

  7. 深入理解JVM : Java垃圾收集器

    如果说收集算法是内存回收的方法论,那么垃圾收集器就是内存回收的具体实现. Java虚拟机规范中对垃圾收集器应该如何实现并没有任何规定,因此不同的厂商.不同版本的虚拟机所提供的垃圾收集器都可能会有很大差 ...

  8. js 去重 字符串 [123123,123123,345435,33467,45645,343467,879,45645]

    function unique(dislodgeArr) { var ret = [] var hash = {} var datasource = new Array(); var array= d ...

  9. Lucene的多线程访问原则和同步,锁机制

    本文介绍lucene多线程环境下的使用原则和commit.lock与write.lock实现的锁机制. 设计之初就是服务于多线程环境,大多数情况下索引会被不至一个线程访问.索引时一个关键资源.在对这样 ...

  10. 新发现。css3控制浏览器滚动条的样式

    &::-webkit-scrollbar-track { background-color: #7e7e7e; } &::-webkit-scrollbar { width: 14px ...