I'm just wondering if it is possible to query a dynamic named xml element using LINQ.
See below sample XML doc:
<code>
<attendees>
<name>linda talor<name/>
<jur_a_credits>1.0<jur_a_credits/>
<jur_a_title>course 1<jur_a_title/>
<jur_f_credits>2.5<jur_f_credits/>
<jur_b_qualifier>self-study<jur_b_qualifier/>
<attendees/>
<code/>
I want now to select al开发者_开发问答l xelement which contains a named "jur" then iterate the list to retrieves its value. Meaning, I want to have below 1.0 course 1 2.5 self-study as in a collection so that I can iterate each of them to get there values.
Is it possible to query it in LINQ?
Sure:
// You could use "Contains" instead of "StartsWith" of course
var query = doc.Descendants()
.Where(x => x.Name.LocalName.StartsWith("jur"))
.ToList();
精彩评论