By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,610 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,610 IT Pros & Developers. It's quick & easy.

appending a new element to an existing xml file

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.