473,378 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

append text to a xml file

I want to append text to element3 and element 4 of a .xml file as
following. The values in first two elements should not be altered and
only the last 2 sholud be changed.

<root>
<element1>aaaa</element1>
<element2>cccc</element2>
<element3>bbbb</element3>
<element4>dddd</element4>
</root>

But using textwriter I could not do this. It gets replaced with the last
two elements . Could you pleas tell me how I can do this??
Thanks a lot

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
2 1996
"Eranga" <km***@yahoo.com> wrote in message
news:em**************@TK2MSFTNGP12.phx.gbl...
I want to append text to element3 and element 4 of a .xml file as
following. The values in first two elements should not be altered and
only the last 2 sholud be changed.

<root>
<element1>aaaa</element1>
<element2>cccc</element2>
<element3>bbbb</element3>
<element4>dddd</element4>
</root>


Is there anything stopping you reading the file into memory, appending the
new children, then saving it back to disk?

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton

Nov 17 '05 #2
Load the XML file into an XmlDocument object and then iterate over the
elements until you find the one you want to modify OR call
GetElementsByTagName passing in the name of the element and then set the
value by using the InnerText property of the returned XmlNode.

After this, just save the file back.

Brian Delahunty
Ireland
"Eranga" wrote:
I want to append text to element3 and element 4 of a .xml file as
following. The values in first two elements should not be altered and
only the last 2 sholud be changed.

<root>
<element1>aaaa</element1>
<element2>cccc</element2>
<element3>bbbb</element3>
<element4>dddd</element4>
</root>

But using textwriter I could not do this. It gets replaced with the last
two elements . Could you pleas tell me how I can do this??
Thanks a lot

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: gukn9700 | last post by:
The following program opens a text file and wants to append new text to it, but everytime I run it, it returns me with "open file fail!". Can anybody help? #include <fstream> #include...
2
by: sm | last post by:
How to "Insert" (not append) new text segment to an existing text file? Assume that we have text file as shown below; Elvis Sofia Kylix BCB--> How to insert here? Atten BuilderX Roma
3
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
0
by: | last post by:
Use the method InsertAfter() from the XmlDocument class or AppendChild from XmlNode class. Here is a short example to use InsertAfter(). http://weblogs.asp.net/sonukapoor/articles/132854.aspx ...
3
by: Craig.Lee | last post by:
I am opening a text file with an ODBC connection. I want to append all the text data to a table. Going row by row and field by field takes too long. Does anyone know how I can either reference the...
2
by: Roy Gourgi | last post by:
Hi, How could I append a text file to another text file. Let's say that I have a File1 and I want to append File2 at the end of File1, how would I do that? TIA Roy
3
by: Macca | last post by:
Hi, I am writing some information to a text file using the TextWriter Class. However I am having problems appending data to a file that already exists and already has text in it. I just seem...
2
by: Gaby Sandoval | last post by:
I have this code. The user can read teh record from the text file just fine. They can click the NEXT button and it reads the next record (which is just the next line from the text file). If the...
1
by: wish | last post by:
Hello, I have problem is when i append new data in text file always append at the last of the text file. Am i can append the new data in beginning of the text file? Mean when i have update data...
1
by: Deshi | last post by:
Hi,. I am trying to append text into the RTF file, nothing seems to be working for me... here is the code FileStream fs = new FileStream("c:\\djj.rtf", FileMode.Append, FileAccess.Write);...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.