將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 回答
- 0 關注
- 305 瀏覽
添加回答
舉報
0/150
提交
取消