How to read XML elements c# (sample code provided) -


i have following xml sample want read data. provided 1 "project" element can have many "project" inside "projects" root.

<?xml version="1.0" encoding="utf-8"?> <projects>   <project>     <details>       <projectname><![cdata[cxwtgzxyt]]></projectname>       <uniqueid>pt144</uniqueid>       <collaboratinglist>         <collaboratingorganisation id="5318" value="epcyxcv rvgxrxayxgpa xcxwtgzxyt"/>         <collaboratingorganisation id="0000" value="epcyxcv rvgxrxayxgpa xcxwtgzxytd"/>       </collaboratinglist>       <researchoutputlist>         <item>           <pubdate>2014-02-04t00:00:00+00:00</pubdate>           <title><![cdata[rgdez]]></title>           <link>link</link>           <guid>guid</guid>           <description><![cdata[ugdb bdsta rgdez]]></description>         </item>         <item>           <pubdate>2015-08-04t00:00:00+00:00</pubdate>           <title><![cdata[aerx capcyz.]]></title>           <link>link</link>           <guid>guid</guid>           <description><![cdata[vwtpy]]></description>         </item>       </researchoutputlist>     </details>   </project> </projects> 

i can read <projectname> , <uniqueid> cannot <researchoutputlist> , <collaboratinglist>. not sure missing or if xml structure correct. codes below:

[serializable]     [xmlroot("projects")]     public class bulkprojectroot     {         public bulkprojectroot()         {             bulkprojectdetails = new list<bulkprojectdata>();         }          [xmlarray("project")]         [xmlarrayitem("details")]         public list<bulkprojectdata> bulkprojectdetails { get; set; }     }   [serializable]     [xmlroot("details")]      public class bulkprojectdata     {         public bulkprojectdata()         {             projectresearches = new list<projectresearchoutputs>();         }          [xmlelement("projectname")]         public string name { get; set; }          [xmlelement("uniqueid")]         public string projectuniqueid { get; set; }          [xmlelement("researchoutputlist")]         public list<projectresearchoutputs> projectresearches { get; set; }      }  [serializable] [xmlroot("researchoutputlist")] public class projectresearchoutputs {     public projectresearchoutputs()     {         researchitemslist = new list<researchoutputitems>();     }      [xmlelement("item")]     public list<researchoutputitems> researchitemslist { get; set; }  }     [serializable]     [xmlroot("item")]      public class researchoutputitems     {          [xmlelement("pubdate")]         public datetime? publishdate { get; set; }          [xmlelement("title")]         public string researchtitle { get; set; }          [xmlelement("link")]         public string researchlink { get; set; }          [xmlelement("guid")]         public string researchguid { get; set; }          [xmlelement("description")]         public string researchdescription { get; set; }      } 

the reasearchlist deserializes fine linqpad, missing collaboration information in bulkprojectdata class.

void main() {     var xml = @"<?xml version=""1.0"" encoding=""utf - 8""?>    <projects>      <project>        <details>          <projectname><![cdata[cxwtgzxyt]]></projectname>          <uniqueid> pt144 </uniqueid>          <collaboratinglist>            <collaboratingorganisation id = ""5318"" value = ""epcyxcv rvgxrxayxgpa xcxwtgzxyt"" />               <collaboratingorganisation id = ""0000"" value = ""epcyxcv rvgxrxayxgpa xcxwtgzxytd"" />                </collaboratinglist>                <researchoutputlist>                  <item>                    <pubdate>2014-02-04t00:00:00+00:00</pubdate>                              <title><![cdata[rgdez]]></title>                              <link> link </link>                              <guid> guid </guid>                              <description><![cdata[ugdb bdsta rgdez]]></description>                            </item>                            <item>                              <pubdate>2015-08-04t00:00:00+00:00</pubdate>                                        <title><![cdata[aerx capcyz.]]></title>                                        <link> link </link>                                        <guid> guid </guid>                                        <description><![cdata[vwtpy]]></description>                                      </item>                                    </researchoutputlist>                                  </details>                                </project>                              </projects>";              var serializer = new xmlserializer(typeof(bulkprojectroot));                     var result = (bulkprojectroot)serializer.deserialize(new stringreader(xml));                          result.dump(); 

enter image description here


Comments