appending a new element to an existing xml file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ofuuzo1@yahoo.no

    appending a new element to an existing xml file

    Hi,
    Is there anyway I can append a new element to an existing xml without
    first loading the existing file into a variable, adding the new
    element into the variable and saving it by overwriting the existing
    file name?

    Thanks
    Ofuuzo
  • Malcolm Dew-Jones

    #2
    Re: appending a new element to an existing xml file

    ofuuzo1@yahoo.n o wrote:
    : On 5 Mar, 14:23, ofuu...@yahoo.n o wrote:
    : Hi,
    : Is there anyway I can append a new element to an existing xml without
    : first loading the existing file into a variable, adding the new
    : element into the variable and saving it by overwriting the existing
    : file name?

    If your concern is the physical act of efficiently adding data to an
    existing file (such as what happens to log files) then I think the two
    ways to do this would be

    -1- Dont add the closing tag until you're finished adding data to the
    file. Simply append each xml-snippet as needed. If you need to manipulate
    the file before you're done then create a copy that has a closing tag.


    -2- Each time you prepend the next set of data you need to truncate the
    file slightly to remove the last line (containing the closing tag). If
    the closing tag is a constant then you know the length to truncate,
    otherwise you need to examine the last N bytes to find the location of the
    last tag, and truncate enough bytes to remove it before appending the new
    data.


    $0.10

    Comment

    Working...