471,120 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,120 software developers and data experts.

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
Mar 5 '08 #1
1 3637
of*****@yahoo.no wrote:
: On 5 Mar, 14:23, ofuu...@yahoo.no 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
Mar 5 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Fnark! | last post: by
reply views Thread by Red Ogden | last post: by
4 posts views Thread by Jesper Stocholm | last post: by
2 posts views Thread by Cat | last post: by
1 post views Thread by onemonk | last post: by
3 posts views Thread by Jim | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.