Storing data into an xml file
I have created a program that the user selects patients and their data and stores them into an xml file. My problem is that if the user selects twice the same patient, the program stores his/her data twice to the xml file.
Is their a function that checks the file before the insertion?
I should read the xml file first and then insert?
Or is their an easier way to do that?
You need to read the XML file anyway, because there is no way to write out a valid XML file by simply appending. So, while you have your data in memory, you can also check it for consistency before writing out.
Since we do not know how your data is selected I would be inclined to keep a QMap of the selections. You can then iterate this map to create you XML, and since it is a map there would be no duplicates or prior to insert you could search the map and if the key does exists ask the user if they want to remove the already selected patient.