appending data to an xml file

T

Thomas Heller

I want to append/insert additional data to an xml file.

Context: I use gccxml to parse C header files. gccxml creates an xml
file containing all the definitions from the header files. The xml
files may be somewhat largish, for 'windows.h' it has more than 5 MB.

Since the xml does not contain #define statements, I want to run gccxml
again with the --preprocess and -dM flags, which dumps out the #define'd
symbols.

I want this information also to be in the same file, but simply
appending it to the xml smells hackish, and I don't know if the latter
xml parsing stage can get this additional data with an error handler, or
somehow else. Maybe I can find the end of the xml data myself, before
giving it to the sax parser.

Better, imo, would be to add the dumped info into a proper xml tag, and
inject it into the original file. Is that (efficiently) possible?

Thomas
 
P

Peter Hansen

Thomas said:
I want to append/insert additional data to an xml file. [...]
Better, imo, would be to add the dumped info into a proper xml tag, and
inject it into the original file. Is that (efficiently) possible?

My technique, when I can't just strip the root element and
have a document fragment consisting of a huge list of the
other elements, is just to seek to the end of the file,
back up to the beginning of the '</xml>', and begin overwriting
the file from that point... seems to work nicely, and in
most cases since I'm the one who wrote the file in the first
place I know that I've written '</xml>\n' and can just
seek to the end minus 8 bytes (when on Windows, anyway...).

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,830
Latest member
HeleneMull

Latest Threads

Top