国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

linqtoxml

2019-11-14 16:13:26
字體:
來源:轉載
供稿:網友

今天在做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;

引入之后一切正常


上一篇:.NET垃圾回收(GC)原理

下一篇:linq讀取xml

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 馆陶县| 新建县| 资中县| 淮南市| 阿拉善左旗| 丹棱县| 湟源县| 哈巴河县| 公主岭市| 清镇市| 友谊县| 凌源市| 咸阳市| 黄大仙区| 延吉市| 务川| 宣武区| 尉氏县| 驻马店市| 青岛市| 蒙城县| 东至县| 富民县| 丰镇市| 郸城县| 韶山市| 三河市| 疏附县| 张家界市| 兴业县| 集贤县| 南充市| 都江堰市| 南乐县| 万宁市| 龙山县| 定西市| 沙雅县| 慈利县| 平顺县| 伊金霍洛旗|