c# - How to parse XML contained in a string to an IList<BusinessObject>? -


i have following xml in string:

<rootelement>   <data>     <row>       <id>1</id>       <name>foo</name>     </row>     <row>       <id>2</id>       <name>bar</name>     </row>        .        .        .   </data> </rootelement> 

and following class:

public class businessobject {     public int id { get; set; }     public string name { get; set; } } 

how can parse data in row elements ilist ( in c# ) ? searched internet few hours couldn't find solve problem. in advance answers

one option, using linq xml:

xdocument doc = xdocument.load(...); var businessobjects = doc.descendants("row")                          .select(x => new businessobject {                                      id = (int) x.element("id"),                                      name = (string) x.element("name")                                  })                          .tolist(); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -