Click here to Skip to main content
11,933,854 members (58,397 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# XML WPF IO XmlReader
Hi all,

i have some doubts in creating xml from a class that i have. I need to grenerate a xml file in my local filesystem the Nodes and Data of a xml should be Generated once from the first time. What ever changed made in the data should be saved in the genereated XML in my local file system using the logic some thing as below.
XmlDocument doc = new XmlDocument();
           // Add a price element.
           XmlElement newElem = doc.CreateElement("price");
           newElem.InnerText = "10.95";
           // Save the document to a file. White space is
           // preserved (no white space).
           doc.PreserveWhitespace = true;
           doc.Save("" + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + UserPrincipal.Current.DisplayName.Replace(' ', '_') + ".xml");

The above example is what i got from MSDN which works fine. what i need is in the LoadXML or using some other method i need to create a XML Using my Custom Class.
Posted 2-Apr-12 18:33pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I guess what you want is XML Serialization to directly store the structure of your objects. See here for more information:[^][^]
Navin Kumar K Subramanian 3-Apr-12 0:35am
Hi thanks,
but how can i read and update the node values in the created file.
Navin Kumar K Subramanian 3-Apr-12 0:45am
And also how can i Generate XML using a Collection i mean using ObservableCollection or Similar type.
Navin Kumar K Subramanian 3-Apr-12 1:56am
i have got the answer here is the code

var imageFile = new FileInfo("test.xml");
if (!imageFile.Exists)
XElement root = XElement.Load("test.xml");
root.Element("Text").SetValue("Hi updated node");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 2 Apr 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100