[Walk trough list and write XML]
Hi everyone.
I'm kinda stuck on a part of my code.
I've a list on wich every position receives an xmldata (custom class). It contains three positions (colorname, colorvalue and xml_filename).
On my method to write xml , i'm trying to setup a foreach statement to write an XML for each xml_filename
i.e: Positions from 0 to 4 have a xml_filename called bla.ppf , positions 5 to 9 have a xml_filename called ble.ppf .
How could i walk trough my list , write the XML based on each xml_filename field of the list ?
I've readed about linq methods for converting the list to xml directly but i know nothing about linq (c# newbie)
Basically: each list position has tree elements from my custom class. The element xml_filename determines which file the field belongs and its attributes. The foreach loop should be something like (foreach item in xmllist) , write one xml using fields where xml_filename is equal (from positions 0 to 5 , example). From positions 6 to 9 another file (field xml_filename will change) and so goes on.
I've posted the whole code on pastebin (big to post here). Thanks !
http://pastebin.com/nrXhumev
Loading
ali tuncerPosted Feb 25, 2016, 8:40 PM
foreach (var filename in grouped)
{
//will take List
writexml(XList.FullList.Where(i => i.xml_filename == filename.Key).ToList(), v);
}
Pablo CostaPosted Feb 25, 2016, 11:56 PM
Pablo CostaPosted Feb 25, 2016, 8:46 AM
Chandu KumawatPosted Feb 25, 2016, 6:27 AM
Chandu KumawatPosted Feb 25, 2016, 6:26 AM
ali tuncerPosted Feb 25, 2016, 6:20 AM
//first group by file names..
var grouped = XMLList.FullList.GroupBy(s => s.xml_filename).Select(grp => new {grp.Key});
foreach (var filename in grouped)
{
WriteToXml(XMLList.FullList.Where(i => i.xml_filename == filename.Key).ToList());
}
Pablo CostaPosted Feb 24, 2016, 10:47 PM
ali tuncerPosted Feb 24, 2016, 9:11 PM
I guess like this :
foreach (xmldata item in XMLList.FullList)
{
}