appending data to an xml file

Discussion in 'Python' started by Thomas Heller, Jan 11, 2005.

  1. 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
     
    Thomas Heller, Jan 11, 2005
    #1
    1. Advertising

  2. Thomas Heller

    Peter Hansen Guest

    Thomas Heller wrote:
    > 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
     
    Peter Hansen, Jan 12, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Red Ogden
    Replies:
    0
    Views:
    1,120
    Red Ogden
    Jul 16, 2003
  2. Emmanuel

    Appending Data to XML File

    Emmanuel, Oct 13, 2006, in forum: Java
    Replies:
    3
    Views:
    334
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Oct 15, 2006
  3. Emmanuel

    appending data to xml file

    Emmanuel, Oct 13, 2006, in forum: XML
    Replies:
    2
    Views:
    461
    Richard Tobin
    Oct 13, 2006
  4. Frank
    Replies:
    1
    Views:
    368
    sloan
    Mar 6, 2007
  5. Replies:
    8
    Views:
    483
Loading...

Share This Page