You can use the Elements
method and provide the name to match. This would allow you to replace the where query with Elements("RoleView")
.
Some other observations:
- You can simplify the first query by grabbing the "Fulfillment" element directly by using the
Element
method, instead ofDescendants
. - The
Value
property returns a string. TheToString()
calls are redundant.
Here's an updated version of your queries:
// if configParms is an XDocument use configParms.Root
var securityRoleName = configParms.Element("Fulfillment")
.Element("SecurityRoleName").Value;
var securedViews = configParms.Descendants("SecurityRoleViews")
.Elements("RoleView")
.Select(node => node.Attribute("name").Value)
.ToList();
var publicViews = configParms.Descendants("PublicRoleViews")
.Elements("RoleView")
.Select(node => node.Attribute("name").Value)
.ToList();