Hello!
I am working on wrapping my head around LINQ. If I had some XML file, such as loaded into an XDocument object:
<Root> <GroupA> <Item attrib1="aaa" attrib2="000" attrib3="true" /> </GroupA> <GroupB> <Item attrib1="bbb" attrib2="111" attrib3="true" /> <Item attrib1="ccc" attrib2="222" attrib3="false" /> <Item attrib1="ddd" attrib2="333" attrib3="true" /> </GroupB> <GroupC> <Item attrib1="eee" attrib2="444" attrib3="true" /> <Item attrib1="fff" attrib2="555" attrib3="true" /> </GroupC> </Root>
I would like to get the attribute values โโof all the child elements of the Item of the Group element. This is what my query looks like:
var results = from thegroup in l_theDoc.Elements("Root").Elements(groupName) select new { attrib1_val = thegroup.Element("Item").Attribute("attrib1").Value, attrib2_val = thegroup.Element("Item").Attribute("attrib2").Value, };
The query works, but if, for example, the groupName variable contains "GroupB", only one result is returned (the first Item element) instead of three. Did I miss something?
source share