Using a loop with xelement class in C# i would like to get the below result!
<data>
<description>Cities that I have recently visited.</description>
<cities>
<city id="1">
<name>Chicago1</name>
<state>IN1</state>
</city>
<city id="2">
<name>Chicago2</name>
<state>IN2</state>
</city>
<city id="3">
<name>Chicago3</name>
<state>IN3</state>
</city>
</cities>
</data>
This is the code i have tried so far! any help?? i need to use a loop and get the above values..The loop i used is commented..
namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
XElement xmlDataStore = new XElement("data",
new XElement("cities",
new XElement("city", new XAttribute("id", "1")),
new XElement ("city","Colombo"),
new XElement("name", "lname"),
new XElement("state", "0772569984")
)
)
;
new XElement("cities",
new XElement("city", new XAttribute("id", "1")),
new XElement ("city","Colombo"),
new XElement("name", "lname"),
new XElement("state", "0772569984")
)
)
;
Console.WriteLine(xmlDataStore);
Console.ReadLine();
}
}
}