0down votefavorite

I've changed my approach and decided to start writing XML with Linq. I've readed some tutorials and was able to write with no problem.

However , i don't know how to write elements iterating over my array of lists.

I've a nested foreach:

Code
 foreach(List<xmldata> i in XMLList.XMLArrayList) {
Code
foreach (var x in i) { } }

that i can use to access elements of my list. Since its an array of list ,

each position of the array is going to have a list with three elements from this class:
Code
 public class xmldata //Class to receive items list
Code
 { public string xml_filename { get; set; }
Code
public string colorname { get; set; }
Code
public string colorvalues { get; set; } }

However, if i directly write x.colorname into the Linq as an XAttribute , in the next

iteration it'll overwrite its value and in the end the fill will have only the last element.

i.e:

Code
List[0][1]
Code
 colorname blue
Code
colorvalue #434344
Code
 xml_filename filename
Code
List[0][2]
Code
colorname cyan
Code
colorvalue #414354
Code
 xml_filename filename
Code
List[0][3]
Code
 colorname magenta
Code
colorvalue #43213
Code
 xml_filename filename

When the foreach loop finishes iterating over this position, the XML File is going to have only the magenta written. And i would like to have all values written (since it'll iterate over all list positions).

How can i achieve that ?

Thanks in advance.