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);
});
C# linq to xml的更多相关文章
- LINQ系列:LINQ to XML类
LINQ to XML由System.Xml.Linq namespace实现,该namespace包含处理XML时用到的所有类.在使用LINQ to XML时需要添加System.Xml.Linq. ...
- LINQ系列:LINQ to XML操作
LINQ to XML操作XML文件的方法,如创建XML文件.添加新的元素到XML文件中.修改XML文件中的元素.删除XML文件中的元素等. 1. 创建XML文件 string xmlFilePath ...
- LINQ系列:LINQ to XML查询
1. 读取XML文件 XDocument和XElement类都提供了导入XML文件的Load()方法,可以读取XML文件的内容,并转换为XDocument或XElement类的实例. 示例XML文件: ...
- Linq to Xml读取复杂xml(带命名空间)
前言:xml的操作方式有多种,但要论使用频繁程度,博主用得最多的还是Linq to xml的方式,觉得它使用起来很方便,就用那么几个方法就能完成简单xml的读写.之前做的一个项目有一个很变态的需求:C ...
- [原创]Linq to xml增删改查Linq 入门篇:分分钟带你遨游Linq to xml的世界
本文原始作者博客 http://www.cnblogs.com/toutou Linq 入门篇(一):分分钟带你遨游linq to xml的世界 本文原创来自博客园 请叫我头头哥的博客, 请尊重版权, ...
- c#操作xml文件(XmlDocument,XmlTextReader,Linq To Xml)
主界面
- Linq对XML的简单操作
前两章介绍了关于Linq创建.解析SOAP格式的XML,在实际运用中,可能会对xml进行一些其它的操作,比如基础的增删该查,而操作对象首先需要获取对象,针对于DOM操作来说,Linq确实方便了不少,如 ...
- LINQ to XML 编程基础
1.LINQ to XML类 以下的代码演示了如何使用LINQ to XML来快速创建一个xml: 隐藏行号 复制代码 ?创建 XML public static void CreateDocumen ...
- XML基础学习02<linq to xml>
Linq to XML的理解 1:这是一种比较好的操作Xml的工具. àXDocument 文档 àXElement 元素 àXAttribute 属性 àXText 文本 2:这里还是和我们之前创建 ...
- C# ~ 从 XML 到 Linq 到 Linq to XML
.XML 可扩展标记语言 (Extensible Markup Language), 标记 (markup) 是关键部分,是标准通用标记语言 (Standard Generalized Markup ...
随机推荐
- 数组中出现次数超过一半的数字 -java
数组中出现次数超过一半的数字 -java 方法一: 数组排序,然后中间值肯定是要查找的值. 排序最小的时间复杂度(快速排序)O(NlogN),加上遍历. 方法二: 使用散列表的方式,也就是统计每个数组 ...
- 能上QQ无法打开网页
能上QQ无法上网电脑故障解决方法 Winsock协议配置故障解决方法 第1步 :单击开始菜单中的运行,并在打开的运行窗口中键入“cmd”并回车确定,打死命令提示符窗口. 第2步 :在打开的命令提示符窗 ...
- spark安装mysql与hive
第一眼spark安装文件夹lib\spark-assembly-1.0.0-hadoop2.2.0.jar\org\apache\spark\sql下有没有hive文件夹,假设没有的话先下载支持hiv ...
- 详解 CSS 属性 - 伪类和伪元素的区别(再也不用概念盲了!!!)
首先,阅读 w3c 对两者的定义: CSS 伪类用于向某些选择器添加特殊的效果. CSS 伪元素用于将特殊的效果添加到某些选择器. 可以明确两点,第一两者都与选择器相关,第二就是添加一些“特殊”的效果 ...
- git clone 命令报错 +diffie-hellman-group1-sha1
解决方法: 在.ssh目录下新建文件config , 添加 Host * KexAlgorithms +diffie-hellman-group1-sha1 到文件config,即可.
- tomcat 发布webService
<!-- tomcat发布webservice时所需jar --> <dependency> <groupId>com.sun.xml.ws</groupId ...
- 10个简单步骤,完全理解SQL
此文章为转载 1. SQL 是一种声明式语言 首先要把这个概念记在脑中:“声明”. SQL 语言是为计算机声明了一个你想从原始数据中获得什么样的结果的一个范例,而不是告诉计算机如何能够得到结果.这是不 ...
- Scala基础入门-代码碎片
import scala.util.control._ import java.util.Date object Test { def main(args: Array[String]) { // v ...
- windows下mysql数据库表名大小写不敏感
最近新入职,领导让做个小功能先练练手.是一个添加分类的功能,有添加和列表,很简单.功能做完后提交,结果在线上出现一个大大的500. 但是我再本地环境下是正常的,我以为可能是php的版本不一致导致的问题 ...
- 用include()和ob_get_contents( )方法 生成静态文件
1. 生成静态文件可以在打开缓冲区的前提下,用include()方法去包含要执行的动态文件,这样该动态文件就会在缓冲区中执行,执行完毕后的静态HTML代码就保存在缓冲区中,然后用ob_get_cont ...