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. -
public string Insert(string XMLFile)
-
{
-
string XMLDirectory = this.xmlDir + this.ProjectorSN + @"\";
-
string file = XMLDirectory + XMLFile;
-
System.Xml.XmlTextWriter writer;
-
-
if (!System.IO.Directory.Exists(XMLDirectory))
-
{
-
System.IO.Directory.CreateDirectory(XMLDirectory);
-
}
-
-
writer = new System.Xml.XmlTextWriter(file, System.Text.Encoding.UTF8);
-
writer.Formatting = System.Xml.Formatting.Indented;
-
writer.WriteStartDocument();
-
writer.WriteStartElement("ProductTest");
-
-
writer.WriteElementString("ProductSN", this.ProjectorSN);
-
writer.WriteElementString("PackageID", this.LightEngineSN);
-
writer.WriteElementString("Part2", this.Lamp1);
-
writer.WriteElementString("Part3", this.Lamp2);
-
writer.WriteElementString("DateTime", this.DateTime);
-
-
writer.WriteWhitespace(" ");
-
// Write End of root element
-
writer.WriteEndElement();
-
-
// Write End of document
-
writer.WriteEndDocument();
-
-
writer.Close();
-
-
return (XMLDirectory + XMLFile + " saved.");
-
}
3 1806
Welcome to TheScripts TSDN....
Try to create a new file stream and set the access to append. - Stream xmlFile = new FileStream(@"c:\path",FileMode.Append);
-
XmlTextWriter textWritter = new XmlTextWriter(xmlFile, Encoding.Default);
-
//author: plazmo
Welcome to TheScripts TSDN....
Try to create a new file stream and set the access to append. - Stream xmlFile = new FileStream(@"c:\path",FileMode.Append);
-
XmlTextWriter textWritter = new XmlTextWriter(xmlFile, Encoding.Default);
-
//author: plazmo
okay i tried that and it worked, only it appended after the endelement of the root.
how do i append just before that?
At this point I suggest you to try XMLDocument, it's more flexible.
If not sure how to use, see this link.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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,...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
| |