Steps in Editing an XML using LINQ and C#
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.
var navResultsPlant = LogXmlDocument.Descendants().Where(
e => e.Attribute("id").Value == id).FirstOrDefault();
if (navResultsPlant != null)
navResultsPlant.Remove();
4. Save.
LogXmlDocument.Save(fullXmlPath);
This blog is dedicated to my experiences in programming. Contributors are welcome, please email me at jhelyn.suan@gmail.com
Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts
Thursday, October 22, 2009
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);
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);
Labels:
Add,
C#,
LINQ,
Save,
Syntax for Adding Record to XML using LINQ
Monday, August 24, 2009
XML and LINQ
How to query in C# using LINQ
XDocument xmlFile = XDocument.Load(filename);
var xt = from y in xmlFile.Descendants("Users").Elements("details")
where y.Attribute("userName").Value == x
select new TempClass
{
Name = y.Element("userdetails").Attribute("userFirstName").Value
};
Download Sample Code Here
Subscribe to:
Posts (Atom)