当前位置:首页 > .NET

Linq读写XML

大滑稽12年前 (2014-03-24).NET1690

         private List<News> GetNews(string html)
        {
            StringReader s = new StringReader(html);
            XDocument loadedData = XDocument.Load("10.xml");
            XElement root = loadedData.Root;//获取根节点
            var data = from query in loadedData.Descendants("entry")
                       select new News
                       {
                           NewsId = (string)query.Element("id"),
                           NewsTitle = (string)query.Element("title"),
                           Summary = (string)query.Element("summary"),
                           AddTime = DateTime.Parse(query.Element("published").Value),
                           NewsUrl = query.Element("link").Attribute("href").Value,
                           DiggsNum = (int)query.Element("diggs"),
                           ViewNum = (int)query.Element("views"),
                           CommentNum = (int)query.Element("comments"),
                           Author = (string)query.Element("sourceName")
                       };
            int linr = data.Count<News>();
            List<News> l = data.ToList<News>();
            return l;
        }

扫描二维码推送至手机访问。

版权声明:本文由第★一★次发布,如需转载请注明出处。

本文链接:https://blog.wpers.net/post/73.html

标签:C#.NET
分享给朋友:

“Linq读写XML” 的相关文章

Cbo控件数据源绑定

 //Cbo控件数据源绑定DataTable DtType = noteType.GetTypeList("");         …

修改注册表限制软件使用次数

private void Form1_Load(object sender, System.EventArgs e){RegistryKey RootKey,RegKey; //项名为:HKEY_CURRENT_USER\Software…

C#修改浏览器主页

string key = @"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main";      &n…

C#获得程序集

 //获得程序集System.Reflection.Assembly assem = System.Reflection.Assembly.GetExecutingAssembly();…

以ToolStrip为例绘制简便背景

//以ToolStrip为例绘制简便背景e.Graphics.FillRectangle(new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Point(…