日期:2014-05-20 浏览次数:20897 次
<?xml version="1.0" encoding="utf-8"?> <root return="0" info="成功" msgid="F830DBA1777415B9" numbers="1" messages="1"/>
void Main() { string str = @"<?xml version=""1.0"" encoding=""utf-8""?> <root return=""0"" info=""成功"" msgid=""F830DBA1777415B9"" numbers=""1"" messages=""1""/>"; var data=XDocument.Parse(str); var query=from x in data.Descendants("root") select new { x.Attribute("msgid").Value }; Console.WriteLine(query.First().Value); //F830DBA1777415B9 }
------解决方案--------------------
//用LOAD也木有发现有什么问题 void Main() { var data=XDocument.Load("C:\\test.xml"); var query=from x in data.Descendants("root") select new { x.Attribute("msgid").Value }; Console.WriteLine(query.First().Value); //F830DBA1777415B9 }