I'm having troubles reading values from an xml file. Here is the xml file:
<root>
<defaultGroups name="Sikker">
<group name="0ASK" />
<group name="0ASKAPP" />
<group name="0ASKFELLES" />
<group name="0SYSAPP" />
<group name="0SYSAPPoffice" />
<group name="10WTS" />
</defaultGroups>
<defaultGroups name="Intern">
<group name="11WTS" />
<group name="1ASK" />
<group name="1ASKAPP" />
<group name="1ASKFELLES" />
<group name="Domain Users" />
<group name="Askvoll brukere" />
<group name="1SYSAPP" />
<group name="1SYSAPPAdobeReader" />
<group name="1SYSAPPEXCEL" />
<group name="1SYSAPPIEXPLORER" />
<group name="1SYSAPPOUTLOOK" />
<group name="1SYSAPPPOWERPOINT" />
<group name="1SYSAPPWORD" />
</defaultGroups>
</root>
With the function shown below, I'm supposed to only read the values from <defaultGroups name="Sikker">
. I do get the first value: "0ASK", but not the rest. Can someone please help me with this? (I'm new to Linq)
This is the C# function I use:
public string GetSikkerSoneDefaultGroups(string companyName)
{
string sikkerSone = "";
XDocument doc = XDocument.Load("xml\\defaults\\" + companyName + ".xml");
var groups = from defaultGroups in doc.Descendants("defaultGroups")
where defaultGroups.Attribute("name").Value == "Sikker"
select new
{
g = defaultGroups.Element("group").Attribute("name").Value
};
foreach (var group in groups)
{
sikkerSone += group.g + ";";
}
doc = null;
return sikkerSone;
}