Read only parts of an XML file

后端 未结 3 495
醉梦人生
醉梦人生 2021-01-29 14:31

 
  RadheyJang 
  India 
  Software Developer 
  

        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-29 14:40

        var ele = XElement.Parse(xml);
        // change to XElement.Load if loading from file  
        var result = ele.Descendants("Section").Zip(ele.Descendannt("Mark"),  (s,m) => new {Section = s.Value, Mark = m.Value}); Now you can create your DataTable:
    
        var table = new DataTable(); 
        var marks = new DataColumn("Mark");
        var sections = new     DataColumn("Sections"); 
        table.Columns.Add(marks); table.Columns.Add(sections); 
        foreach (var item in result) 
        {   
         var row = table.NewRow();   
         row["Mark"] = item.Mark;     
         row["Sections"] = item.Section; 
         table.Rows.Add(row);
        } 
    

    Try this Code ..

提交回复
热议问题