r3nder
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");
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER