0

I'm working on an XML file editor in C# that loads multiple xml files into a datagridview for editing. I'm having trouble determining the best way to save changes.

Each XML file has the same schema but different data. I'm using linq to query and load the data from each XML into a datagridview.

I need to edit the values displayed in the datagridview and have the changes saved back to the related XML file.

What would be the best way of doing this? Will I need to read in the filepath to the grid as well and then use something like WriteXML along with the filepatch to determine what file to write to?

Fisher8370
  • 47
  • 4
  • Hi, you can use the Xml Linq ( XDocument ) class to do that, may this question helps you https://stackoverflow.com/questions/544310/best-way-to-change-the-value-of-an-element-in-c-sharp – Rebin Qadir Jan 12 '20 at 20:44
  • I would create a link between the datagrid rows and the xml nodes. Then when a row of the datagrid is updated I would put the results back into the xml node. I think this is easier than deserializing the entire xml and then serializing the datagrid. But it depends on the structure of the xml file my method or serialize/deserialize is better. I like using xml linq, but the best method using xml depends on the size of the file, the number of nodes you need to parse, and the structure of the xml. In this case it may be best to use the DataSet methods ReadXml and WriteXml. – jdweng Jan 12 '20 at 22:00
  • I would be reading anywhere from 20-200 files into the grid. Each could be anywhere from 500K to 1.5MB. Each file has multiple nodes with the same structure that contains the data that's read into each row of the grid. Each node has an ID that exists as unique in each file but will likely appear in others. So it seems that the best way is to use the file and that ID to find the node in the XML and update with WriteXML? That was my original thought, but wanted to see if there was anyway that might be better. – Fisher8370 Jan 14 '20 at 00:31

0 Answers0