I need help. I'm trying to figure out a way to read inside a bracket like this one:
<group id = "56">
<name>Counter</name>
</group>
In the code, there are mulitiple places where the same pattern comes back, and I would like to get all the group id number's and their name.
This is my code:
XDocument doc = XDocument.Parse(_XmlFile);
var results = doc.Descendants("group").Select(x => new
{
id = (int)x.Attribute("id"),
name = x.Attribute("name").Value,
}).ToList();
Console.WriteLine(results);
Thanks
XElementtoint. You need to parse theValuewhich is astring. 2.nameis not an attribute but a child element togroup.XNodehas cast operators.XAttributein this case... Which does not inherit fromXNode... ButXAttributehas the same cast operators as well...