zoukankan      html  css  js  c++  java
  • linq to xml

    今天在做xml解析的时候,引入命名空间

    using System. Xml. Linq;

    然后

    XElement news = root. Element( "newslist" );
    NewsUnit[ ] units = news. Elements( "news" ). Select(
                                n => new NewsUnit
                                {
                                    id = n. Element( "id" ). Value. ToInt32( ),
                                    title = n. Element( "title" ). Value,
                                    author = n. Element( "author" ). Value,
                                    authorID = n. Element( "authorid" ). Value. ToInt32( ),
                                    pubDate = n. Element( "pubDate" ). Value,
                                    commentCount = n. Element( "commentCount" ). Value. ToInt32( ),
                                    url = n.Element("url") == null ? null : n.Element("url").Value,
                                    newsType = new NewsType
                                    {
                                        type = n. Element( "newstype" ). Element( "type" ). Value. ToInt32( ),
                                        attachment = n.Element("newstype").Element("attachment") == null ? 
                                                                                        n. Element( "id" ). Value : 
                                                                                        n. Element("newstype"). Element("attachment").Value,
                                        authorID = n. Element( "newstype" ). Element( "authoruid2" ). Value. ToInt32( ),
                                    },
                                }
                            ). ToArray( );

    结果说没有Select方法,

    原因是没有引入

    using System. Linq;

    引入之后一切正常

  • 相关阅读:
    mybatis的缓存机制
    mybatis动态SQL
    mybatis关联集合List&分布查询传递多列值
    winrt获取文件MD5码
    在wpf中使用winrt的Toast弹框效果
    winrt控件
    WdatePicker组件不显示
    Thread.Sleep in WinRT
    google 语音api
    UTF8编码转换(C#)
  • 原文地址:https://www.cnblogs.com/wanghongxu/p/4224095.html
Copyright © 2011-2022 走看看