ConditionRacer
ConditionRacer

Reputation: 4498

C#: Keeping an xml file in sync with data model

Lets say I have a List<Book> that a user can add/remove books to/from. The list is persisted to an xml file so that the data is available between sessions on a website.

Now, obviously this is not an ideal solution, a database would be much nicer. But this is for a school project with some rigid constraints. What I'm trying to figure out is if there is a good way to "update" the xml file whenever the List<Book> changes instead of simply rewriting the entire file each time.

Upvotes: 1

Views: 389

Answers (1)

Alexei Levenkov
Alexei Levenkov

Reputation: 100547

No*, it is not possible to "update" XML without rewriting whole file. XML format does not allow for in-place modifications or even simple append.

*) one can come up with clever ways of allowing some in-place updates (i.e. leaving extra white-space and caching file offsets of elements) but I'd recommend doing such things only for personal entertainment project.

Upvotes: 3

Related Questions