473,395 Members | 1,631 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,395 software developers and data experts.

how do i append to xml files

abehm
35
Hi,
I have a method that inserts class data into a new xml document, however I would like to append the data after the last element of an existing xml document.

here is the code I have:
if anyone can offer any help or suggestions, that would be appreciated.

Expand|Select|Wrap|Line Numbers
  1. public string Insert(string XMLFile)
  2.     {
  3.         string XMLDirectory = this.xmlDir + this.ProjectorSN + @"\";
  4.         string file = XMLDirectory + XMLFile;
  5.         System.Xml.XmlTextWriter writer;
  6.  
  7.         if (!System.IO.Directory.Exists(XMLDirectory))
  8.         {
  9.             System.IO.Directory.CreateDirectory(XMLDirectory);
  10.         }
  11.  
  12.         writer = new System.Xml.XmlTextWriter(file, System.Text.Encoding.UTF8);
  13.         writer.Formatting = System.Xml.Formatting.Indented;
  14.         writer.WriteStartDocument();
  15.         writer.WriteStartElement("ProductTest");
  16.  
  17.         writer.WriteElementString("ProductSN", this.ProjectorSN);
  18.         writer.WriteElementString("PackageID", this.LightEngineSN);
  19.         writer.WriteElementString("Part2", this.Lamp1);
  20.         writer.WriteElementString("Part3", this.Lamp2);
  21.         writer.WriteElementString("DateTime", this.DateTime);
  22.  
  23.         writer.WriteWhitespace(" ");
  24.         // Write End of root element
  25.         writer.WriteEndElement();
  26.  
  27.         // Write End of document
  28.         writer.WriteEndDocument();
  29.  
  30.         writer.Close();
  31.  
  32.         return (XMLDirectory + XMLFile + " saved.");
  33.     }
May 18 '07 #1
0 878

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: waters | last post by:
I seem to have hit a snag. I am trying to add the list (l_local) as an item in the output list (l_output). "l_local" is a modified copy of the format-list "l_format", which will be updated by...
1
by: David Barger | last post by:
Greetings, It appears that an Append Query I run in Access XP is randomly failing to append a field. I have payroll data being entered into a payroll database. This data is exported daily to...
8
by: WordVBAProgrammer | last post by:
I've been struggling with this for a few days now. It worked originally as plain VB-type strings, but for some reason ceased creating the FileNm. I changed the code to use StringBuilder, but...
3
by: Mohan | last post by:
Hi I face a problem with the stl string append on our 32-bit SLES9 machine . (It is not happening on SLES9 64-bit machines and on SuSE 10). When we read a 179MB file into the memory,...
12
by: vj | last post by:
I am using Borland C++. I run a program which generates output data files, say 'Voltage.dat', 'Current.dat'. I have a variable in my code (say N), and for various values of N (for each value of...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.