zoukankan      html  css  js  c++  java
  • 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);
    });

  • 相关阅读:
    欧拉回路 定理
    UESTC 1087 【二分查找】
    POJ 3159 【朴素的差分约束】
    ZOJ 1232 【灵活运用FLOYD】 【图DP】
    POJ 3013 【需要一点点思维...】【乘法分配率】
    POJ 2502 【思维是朴素的最短路 卡输入和建图】
    POJ 2240 【这题貌似可以直接FLOYD 屌丝用SPFA通过枚举找正权值环 顺便学了下map】
    POJ 1860【求解是否存在权值为正的环 屌丝做的第一道权值需要计算的题 想喊一声SPFA万岁】
    POJ 1797 【一种叫做最大生成树的很有趣的贪心】【也可以用dij的变形思想~】
    js 实现slider封装
  • 原文地址:https://www.cnblogs.com/fx2008/p/3243688.html
Copyright © 2011-2022 走看看