Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. HOW CAN I WRITE XML FROM LIST COLLECTION ???

HOW CAN I WRITE XML FROM LIST COLLECTION ???

Scheduled Pinned Locked Moved .NET (Core and Framework)
questionxml
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TARAK NATH ROY
    wrote on last edited by
    #1

    HOW CAN I WRITE XML FROM LIST COLLECTION ??? I have List like KeyValuePair<int, List<Point2D>> arcCollection here total item in arcCollection is 30. i.e arcCollection.count =30 And each List<Point2D>> i have stored 3 points(x1,y1 x2y2 x3y3) Each there any way out that to write XML of value of List<Point2D>> for each arcCollection.count wthe regards tarak

    0 T 2 Replies Last reply
    0
    • T TARAK NATH ROY

      HOW CAN I WRITE XML FROM LIST COLLECTION ??? I have List like KeyValuePair<int, List<Point2D>> arcCollection here total item in arcCollection is 30. i.e arcCollection.count =30 And each List<Point2D>> i have stored 3 points(x1,y1 x2y2 x3y3) Each there any way out that to write XML of value of List<Point2D>> for each arcCollection.count wthe regards tarak

      0 Offline
      0 Offline
      0x3c0
      wrote on last edited by
      #2

      Look into XDocument and LINQ. You could also add the items using a loop. If all else fails, then this piece of C# code should give you the general idea:

      using System.Xml.Linq;
      
         XDocument xDoc = new XDocument(new XElement("root",
                  new XElement("key", arcCollection.Key),
                  new XElement("values",
                      from Point pt in arcCollection.Value
                      select new XElement("point",
                          new XElement("x", pt.X),
                          new XElement("y", pt.Y)
                      )
                  )
              ));
      

      That piece of code iterates through every Point structure in arcCollection.Value, and creates a nice neat XML structure. I didn't have the Point2D structure definition with me, so I used the Point structure instead, but this is still fairly neat. If you need to add properties, then look at the lines which reference pt.X and pt.Y. They form a list, and you simply have to add the properties as XElements like I did. Don't forget to change the definition of pt to a Point2D structure though, otherwise the code probably won't even compile

      1 Reply Last reply
      0
      • T TARAK NATH ROY

        HOW CAN I WRITE XML FROM LIST COLLECTION ??? I have List like KeyValuePair<int, List<Point2D>> arcCollection here total item in arcCollection is 30. i.e arcCollection.count =30 And each List<Point2D>> i have stored 3 points(x1,y1 x2y2 x3y3) Each there any way out that to write XML of value of List<Point2D>> for each arcCollection.count wthe regards tarak

        T Offline
        T Offline
        Tristan Rhodes
        wrote on last edited by
        #3

        XmlSerializer. Although you might need to modify your object hierachy. You can read/write the serialized object output to streams and files.

        ------------------------------- Carrier Bags - 21st Century Tumbleweed.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups