Select only attributes of parent element

PapaSmurf

New Member
I have the following XML:\[code\]<data name="zzz_AbsenceReportDR" time="2012-06-19 13:36:40Z" xmlns=""> <row conf="88945498" date="6/19/2012" employee_identifier="mickeymouse" school_name="City Academy" substitute_identifier="" start_time_absence="7:15:00 AM" end_time_absence="3:00:00 PM" filled="No" school_external_id="309" school_dbkey="83235" notes_to_administrator="My lesson plans are in my mailbox." notes_only_for_administrators="" last_update="6/18/2012 6:00:24 PM" notes="We have PE on Monday." last_approval_action="" created="6/18/2012" cancelled="No" absence_last_update="6/18/2012 6:00:24 PM" absence_reason="Personal" approval_status="Unapproved" approved_by="" needs_approval="Yes" /> <row conf="88946034" date="6/19/2012" employee_identifier="AntwanTeacher" school_name="College Academy" substitute_identifier="" start_time_absence="7:30:00 AM" end_time_absence="3:30:00 PM" filled="No" school_external_id="213" school_dbkey="83244" notes_to_administrator="" notes_only_for_administrators="" last_update="6/18/2012 7:00:24 PM" notes="Lesson Plan on Desk" last_approval_action="" created="6/18/2012" cancelled="No" absence_last_update="6/18/2012 7:00:24 PM" absence_reason="Personal" approval_status="Unapproved"approved_by="" needs_approval="Yes" /> <row conf="88946035" date="6/19/2012" employee_identifier="vinnieteacherman" school_name="Oakland Academy" substitute_identifier="" start_time_absence="7:35:00 AM" end_time_absence="3:10:00 PM"filled="No" school_external_id="207" school_dbkey="83242" notes_to_administrator="" notes_only_for_administrators="" last_update="6/18/2012 7:00:24 PM" notes="" last_approval_action="" created="6/18/2012" cancelled="No" absence_last_update="6/18/2012 7:00:24 PM" absence_reason="Personal" approval_status="Unapproved" approved_by="" needs_approval="Yes" />\[/code\]The rows are generated dynamically and (at some point in the future) may have an attribute called "name". What is the LINQ expression to select the value of the name attribute from only the data (parent) element? I'm using the following code, but am worried that it would also return row attributes called "name".\[code\]var xElems = from x in xmlDoc.Descendants() where x.Name.LocalName == "data" select x;foreach (var xElem in xElems){ Console.WriteLine(xElem.Attribute("name"));}\[/code\]
 
Back
Top