将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);}相关分类