XML / JSON works best if you write the entire document right away, an attempt to add data may also be fine, but at some point you probably want to insert / update partial data in the middle of the document / file and that is, when it getting hairy.
If you can live with a solution that reads data in memory (either directly or partially by query), and then at some later point writes everything back to a file, then it works well with a single XML / JSON file. Until you need to periodically update / insert / delete partial data from a file, the file should do this (although performance may be a problem).
One way that I have used many times is to define an XSD schema , including constraints, data types, etc. at your discretion, and then configure the pre-build step, which automatically generates a serializable hierarchy of C # classes for you (using, for example, XSD.exe ). Using normal funcationality XML serialization, then it is very easy to load (and, if necessary, check the XML through your XSD document) the entire document into memory, read / process it (query / update / insert / delete), and then serialize the entire hierarchy of objects back in XML.
See this page for information on XSD.exe .
This approach quickly gives you a pretty useful and solid foundation for development. This should be enough for a while, but you may need to rewrite it a bit if you later move to a database-based solution, if you do not distract access to the data from the inside from the very beginning.
If a clean file-based solution is not enough, go for some kind of database-oriented solution, preferably some kind of built-in database such as SqlLite or BerkeleyDb .
source share