C# linq to xml
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);
});
相关文章
- Getting Started with MongoDB (C# Edition)
- Lua与C#传参
- C# DateTime的11种构造函数 [Abp 源码分析]十五、自动审计记录 .Net 登陆的时候添加验证码 使用Topshelf开发Windows服务、记录日志 日常杂记——C#验证码 c#_生成图片式验证码 C# 利用SharpZipLib生成压缩包 Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库
- 请求大神,C#如何截取字符串中指定字符之间的部分 按指定字符串分割 一分为二 c# 去除字符串中的某个已知字符
- c# 把一个匿名对象赋值给一个Object类型的变量后,怎么取这个变量? c# dynamic动态类型和匿名类 详解C# 匿名对象(匿名类型)、var、动态类型 dynamic 深入浅析C#中的var和dynamic
- wpf 导出Excel Wpf Button 样式 wpf简单进度条 List泛型集合对象排序 C#集合
- [C#基础]c#中的BeginInvoke和EndEndInvoke
- C# 字符串拼接性能探索 c#中+、string.Concat、string.Format、StringBuilder.Append四种方式进行字符串拼接时的性能
- asp.net, c#,获取时间大全,时间运算,时间格式符号对照表
- C#操作Word Aspose.Words组件介绍及使用 基本介绍与DOM概述
- C# 快速高效率复制对象另一种方式 表达式树
- C# 中xml数组的序列和反序列化方法
- C# list 去重
- c#基础-的显性转换,和隐形转换
- 《C#零基础入门之百识百例》(四十)方法应用 -- 推箱子游戏 -- 代码分析
- 《C#零基础入门之百识百例》(九十二)本地数据交互 -- 文件概述 -- File类介绍和使用
- c#操作xml文件
- C#实现对象序列化为XML
- C#-How to use less than sign and greater than sign symbols in xml query?
- C#-xml-读取节点数据方法
- 《[C#] int与System.Int32有什么区别》
- C# 创建XML文档
- 【C#/WPF】Button按钮动态设置Background背景颜色