Click here to Skip to main content
13,510,493 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
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")

    )    
            )
                ;

           //var list = from x in XElement.ReadFrom(xmlDataStore).Element("Node").Elements() 
           //select new
           //{
           //   Name = x.Name,
           //   Value = (string)x
           //};


            Console.WriteLine(xmlDataStore);
            Console.ReadLine();

        }


    }
}
Posted 25-Jul-13 22:41pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.180417.1 | Last Updated 26 Jul 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100