将Linq与XML命名空间结合使用我有个密码:/*string theXml =
@"<Response xmlns=""http://myvalue.com""><Result xmlns:a=""
" xmlns:i=""
</Response>";*/string theXml = @"<Response><Result><TheBool>true</TheBool><TheId>1</TheId></Result></Response>";
XDocument xmlElements = XDocument.Parse(theXml);var elements = from data in xmlElements.Descendants("Result")
select new {
TheBool = (bool)data.Element("TheBool"),
TheId = (int)data.Element("TheId"),
};foreach (var element in elements){
Console.WriteLine(element.TheBool);
Console.WriteLine(element.TheId);}当我对Xml使用第一个值时,结果为NULL,而对于第二个值,我有很好的值.如何通过xmlns值将Linq用于XML?
3 回答
- 3 回答
- 0 关注
- 290 浏览
添加回答
举报
0/150
提交
取消