Thursday, October 1, 2009

Syntax for Adding Record to XML using LINQ

XML Hierarchy




Steps in Adding

1. Get the path of your XML file.

string fullXmlPath =
System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "file name.xml";

2. Load the path.

XElement LogXmlDocument = XElement.Load(fullXmlPath);

3. Prepare the data.

LogXmlDocument.Add
(new XElement
("Property",
new XAttribute("id", newid),
new XAttribute("iid", sid),
new XElement("Identification", id),
new XElement("Description", desc),
new XElement("Manufacturer", manufac)
);

4. Save.

LogXmlDocument.Save(fullXmlPath);

No comments:

Post a Comment

About Me

My photo
simple and straight forward