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
- 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.");
- }