Reputation: 16081
I'm trying to grab/select certain xml elements that are deeply nested in a .vcxproj file. So far, I'm not having any luck. No matter what I do, my linq query is coming up empty:
private static void CheckProject(FileSystemInfo file)
{
Console.WriteLine(file.FullName);
XDocument doc = XDocument.Load(file.FullName);
var elems = from elem in doc.Descendants()
where elem.Name == "Link"
select elem;
foreach (XElement elem in elems)
{
Console.WriteLine(elem.Name);
}
}
I also tried this linq query, to no avail:
var elems = from elem in doc.Descendants("Link")
select elem;
Upvotes: 2
Views: 319
Reputation: 6805
You need to compare the LocalName, not the XName.
var elems = doc.Descendants().Where(e=> e.Name.LocalName == "Link");
foreach (XElement elem in elems)
{
Console.WriteLine(elem.Name.LocalName);
}
Upvotes: 2