Link to home
Start Free TrialLog in
Avatar of r3nder
r3nderFlag for United States of America

asked on

writing all the additions to xml at once

I have a file in xml and I am appending to it - I don't want to append 1 list at a time I want it to write them all then save. I tried putting the xdoc.save outside the foreach loop but I don't think that worked - any ideas?
                        List<InvictusRTDatabase.ChartData> updateList = new List<InvictusRTDatabase.ChartData>();
                        foreach (var s in comparedList)
                        {
                            XDocument xdoc = new XDocument();
                            updateList = irtd.getDifference(Convert.ToInt32(jobID), s.Surveyid);
                            foreach (var item in updateList)
                            {
                                xdoc = XDocument.Load(path + "\\" + jobID + ".xml");
                                XElement Survey = xdoc.Element("Surveys");
                                Survey.Add(new XElement("Survey",
                                           new XElement("SurveyID", item.SurveyID.ToString()),
                                           new XElement("ChartDataUID", item.ChartDataUID.ToString()),
                                           new XElement("ChartDataTime", item.ChartDataTime.ToString()),
                                           new XElement("FilteredDataPoint", item.filteredDataPoint.ToString()),
                                           new XElement("rawDataPoint", item.rawDataPoint.ToString()),
                                           new XElement("Centroid", item.Centroid.ToString()),
                                           new XElement("CentroidOffset", item.CentroidOffset.ToString())
                                           ));
                                xdoc.Save(path + "\\" + jobID + ".xml");
                            }
                           
                        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CuteBug
CuteBug
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of r3nder

ASKER

Holy Crap that was fast - 5 megs in literarily 2 seconds Thanks Bug