appending data to an xml file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Heller

    #1

    appending data to an xml file

    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
  • Peter Hansen

    #2
    Re: appending data to an xml file

    Thomas Heller wrote:[color=blue]
    > I want to append/insert additional data to an xml file.[/color]
    [...][color=blue]
    > 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?[/color]

    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

    Comment

    Working...