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. 网路流程图 TCP/IP

  2. web开发(Java&Jquery)实现验证码

    1. Ajax Fancy Capcha 一个支持 Ajax 又很炫的 jQuery Captcha 插件,它使用了很人性化的验证机制. ​ from : http://www.webdesignbe ...

  3. 13个JavaScript图表(JS图表)图形绘制插件

    转自:http://blog.jobbole.com/13671/ 1. Flash 过去是最佳解决方案,但很多人多在从那迁移: 2. 现代浏览器及其更强大的计算能力,使其在转化绘制实时数据方面的能力 ...

  4. linux 启动 oracle数据库

    第一步:切换到oracle用户 su - oracle 第二步:启动oracle数据库监听 lsnrctl start 第三步:输入下方命令,出现:sql> sqlplus /nolog 第四步 ...

  5. mysql数据库的物理文件结构

    mysql两种常用存储引擎myisam和innodb myisam不支持事务:innodb支持事务,当前作为插件来安装 myisam的数据库的物理文件结构为: .frm文件:与表相关的元数据信息都存放 ...

  6. git创建分支

    1.创建本地分支名称为dev的本地分支 git branch dev 2.将本地分支添加到远程分支 git push origin dev 3.查看创建的本地分支, 带有*符号的分支,代表当前所在分支 ...

  7. JS(移动端)自己封装移动端一些常用方法

    /** * Created by Administrator on 2016/7/14. */ /*命名空间*/ window.lcf = {}; /*监听过渡结束的方法*/ lcf.transiti ...

  8. Android 上多方式定位元素(python)

    Android 上多方式定位元素(python) 在学习实际UI自动化测试的时候,首先就需要定位元素,然而定位元素也是最头疼的地方,因为元素各种控件名称的缺失会影响元素的准确定位.下面针对Androi ...

  9. zoj1027 Human Gene Functions

    一道动态规划,两个串进行匹配,不同字母匹配的值不一样,也可以和空格匹配(空格不能与空格匹配),求最大的匹配值. 数据很弱,每个串都在100以内. 定义dp[i][j]为第一个串前i个数和第二个串前j个 ...

  10. 解决chrome下上传文件 返回值带 <pre style="word-wrap:break-word;white-space:prewrap;"></pre>

    解决办法:后台 response.setContentType("text/html");