mvbl fst
mvbl fst

Reputation: 5263

Appending nodes to XML files without first reading the file

If I want to store data about a certain resource in an XML file but for speed sake I don't want to first read the file and then re-write it, I want to append to existing file. But if it's a valid XML file than it has to have only a single root element, and if it's closed, than appending new node will be make XML file invalid. Any suggestions for what to do?

Upvotes: 0

Views: 142

Answers (1)

Miklos Csuka
Miklos Csuka

Reputation: 1509

You did not write which programming language you want to use. In C, open the file with 'r+' flag, navigate to the beginning of the end tag, then write the new element and the end tag.
On the other hand, probably this is the case when you should use plain text file, instead of XML. Is there a reason it has to be XML?

Upvotes: 1

Related Questions