栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Linq到具有Xml名称空间的Xml

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Linq到具有Xml名称空间的Xml

LINQ到XML的方法,如

Descendants
Element
采取
XName
作为参数。有一个从转换
string
XName
时自动发生的事情给你。您可以通过
XNamespace
Descendants
Element
调用中的字符串之前添加一个来解决此问题。请注意,因为您有两个不同的名称空间在工作。

string theXml =     @"true1"; //string theXml = @"true1";    Xdocument xmlElements = Xdocument.Parse( theXml );    XNamespace ns = "http://myvalue.com";    XNamespace nsa = "http://schemas.datacontract.org/2004/07/My.Namespace";    var elements = from data in xmlElements.Descendants( ns + "Result" )          select new      {          TheBool = (bool) data.Element( nsa + "TheBool" ),          TheId = (int) data.Element( nsa + "TheId" ),      };    foreach ( var element in elements )    {        Console.WriteLine( element.TheBool );        Console.WriteLine( element.TheId );    }

注意ns中的ns

Descendants
和nsa中的使用
Elements



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/470784.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号