XML find value under specific element
I need a method that has one input argument (aPath) and a boolean return value. I want to check if the input is under "Mandatory" element. For instance: IsMandatory(@"\documents");
this is the xml:
<?xml version="1.0" encoding="utf-8" ?>
<strategy>
<mandatory&g开发者_开发知识库t;
<path>\\documents</path>
<path>\\movies</path>
<path>\\sounds</path>
</mandatory>
<optional>
<path>\\images</path>
</optional>
<ignored />
</strategy>
Something like:
bool exists = XElement.Parse(xml).Descendants("mandatory")
.Elements("path").Any(p => p.Value == aPath);
Note that with the content in the origianl question, this will return true for:
string aPath = @"@""\documents\""";
which is to say, a string with the internal value @"\documents\"
精彩评论