Sorry if this question is very basic, but I haven't worked with XML very much, and this is my first time working with LINQ to XML...
I have an XML sitemap that is structured like a directory tree:
<Site>
<File GUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx">FileName</file>
<Folder name="FolderName">
<Security>
<Role>Admin</role>
</Security>
<File GUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx">FileName</file>
<Folder name="subFoler">
<File GUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx">FileName</file>
<File GUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx">FileName</file>
<Folder>
<File GUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx">FileName</file>
</Folder>
</Folder>
</Folder>
</Site>
In this way, every file will inherit security from its parent folder (or grandparent folder, etc, depending upon how far up the tree the <security></security>
is located.
I want to be able to, given a file's GUID, select that file with LINQ, and gather all of the roles associated with the security that file has inherited.
This is what I have so far, but it is a very rough attempt, and is not complete:
XDocument sitemap = XDocument.Load(@"\sitemap.xml");
XElement currentFile = new XElement("File",
from file in sitemap.Elements("File")
where file.Element("GUID").Equals(guid)
select file.Parent.Element("security").Elements("role"));
ps. The sitemap file is located within the same directory as the class in which this code is written