HOW CAN I WRITE XML FROM LIST COLLECTION ???
-
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
-
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
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
andpt.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 ofpt
to a Point2D structure though, otherwise the code probably won't even compile -
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
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.