I have a tree in form of XML
that stores it in XELement
variable.How I can search a value in All Nodes in this XML and if it exists return true
?
Asked
Active
Viewed 1,380 times
1

abatishchev
- 98,240
- 88
- 296
- 433

Arian
- 12,793
- 66
- 176
- 300
2 Answers
4
Try this:
bool result = element.DescendantsAndSelf().Any(e => e.Value == "cccc");

Hamlet Hakobyan
- 32,965
- 6
- 52
- 68
0
for searching a Value i couldnt find anything and i wrote this :
wfo = XElement.Load("some xml");
foreach (var element in wfo.DescendantsAndSelf())
{
foreach (XAttribute attribute in element.Attributes())
{
if (attribute.Value.Any(q=>q== "search"))
{
}
}
}
}
linq :
var test = wfo.DescendantsAndSelf().Attributes().Any(q => q.Value.Any(z=>z == "search"));

Mahdi Khalili
- 1,025
- 15
- 32