c# - simple way to read xml data using linq -


i have xml structure this. can simple linq function read xml structure.the itementry node repeats according data. tried read xml using method below,but getting no records in list. method here correct way details...

list<cx_itemlist> slist =     (from e in xdocument.load(param.filename).root.elements("itementry")      select new cx_itemlist      {          title = (string)e.element("title"),          year = (string)e.element("year"),          itemname = (string)e.element("itemname"),          catrylist =          (              p in e.elements("categorylist").elements("categories")              select new catlist              {                  idtype = (string)p.element("categoryid"),                  idnumber = (string)p.element("categoryname")              }).tolist()      }).tolist(); 
<itemslist>  <iteminformation>   <itemdate>01/23/2014</itemdate>   <itemcount>57</itemcount>  </iteminformation>  <itementry>   <title>title1</title>   <year>2013</title>   <itemname>testname</itemname>   <categorylist>   <categories>    <categoryid>category1</categoryid>    <categoryname>category2</categoryname>   </categories>   <categories>    <categoryid>category1</categoryid>    <categoryname>category2</categoryname>   </categories>   </categorylist>  </itementry>  <itementry>   <title>title1</title>   <year>2013</title>   <itemname>testname</itemname>   <categorylist>   <categories>    <categoryid>category1</categoryid>    <categoryname>category2</categoryname>   </categories>   <categories>    <categoryid>category1</categoryid>    <categoryname>category2</categoryname>   </categories>   </categorylist>  </itementry> </itemslist> 

you should try xdocument.

xdocument xdoc = xdocument.load("file.xml"); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -