C# 使用linq获取特定的xml行
我有一个如下所示的XML:C# 使用linq获取特定的xml行,c#,xml,linq,C#,Xml,Linq,我有一个如下所示的XML: <data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <row> <Alert>warning</Alert> </row> </data> 我知道我的linq有点问题,但我对linq很陌生,希望得到一些帮助 谢谢 我希望这能奏效。请试试这个 XNamespace ns = "http://www.w3.org/200
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<Alert>warning</Alert>
</row>
</data>
我知道我的linq有点问题,但我对linq很陌生,希望得到一些帮助
谢谢 我希望这能奏效。请试试这个
XNamespace ns = "http://www.w3.org/2001/XMLSchema-instance";
var xDocument = XDocument.Load("path");
var result = xDocument.Descendants(ns + "row").ToList();
var xDocument = XDocument.Load(@"XmlFilePath");
//Use below if you have xml in string format
// var xDocument = XDocument.Parse("XmlString");
XNamespace ns = xDocument.Root.GetDefaultNamespace();
var result = xDocument.Descendants(ns + "row").ToList();
var xDocument = XDocument.Load(@"XmlFilePath");
//Use below if you have xml in string format
// var xDocument = XDocument.Parse("XmlString");
XNamespace ns = xDocument.Root.GetDefaultNamespace();
var result = xDocument.Descendants(ns + "row").ToList();