C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » XML »

how to write data into an xml file


Posted Date: 10 Nov 2008      Posted By: ashok      Member Level: Bronze     Points: 1   Responses: 3



Hi All,
i am having a c# windows application,using which i need to edit an existing XML file and add change the data over there and save it.

how can I do it.

References or Code will be helpful

thanks,
Ashok





Responses

Author: vipul    10 Nov 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

http://www.google.co.in/search?hl=en&rlz=1G1GGLQ_ENIN299&q=add+edit+xml+file+in+c%23+2005&btnG=Search&meta=

you used this link you get your answer.

vipul,

Please Rate This Answer If They Helpful

Thanks & Regards
Patel Vipul



Author: Anil Kumar Pandey    10 Nov 2008Member Level: DiamondRating:     Points: -20

hi,


please see the following function... This might help u...


public void createXML()
{
XmlDocument doc = new XmlDocument();


string filename="c:\\sample.xml";
XmlTextWriter tw=new XmlTextWriter(filename,null);//null represents the Encoding Type//
tw.Formatting=Formatting.Indented; //for xml tags to be indented//

//tw.WriteStartDocument(); //Indicates the starting of document (Required)//


//tw.WriteStartElement("Employees");
//tw.WriteStartElement("Employee","Genius");
//tw.WriteAttributeString("Name","krishnan");
//tw.WriteElementString("Designation","Software Developer");
//tw.WriteElementString("FullName","krishnan Lakshmipuram Narayanan");

tw.WriteStartElement("Author");
tw.WriteElementString("ID","1");
tw.WriteElementString("SubmissionDate","1-1-08");
tw.WriteElementString("Topic","test");
tw.WriteElementString("Title","test");
tw.WriteStartElement("Authors");
tw.WriteStartElement("Author");
tw.WriteElementString("Name","XYZ");
tw.WriteElementString("Affiliation","ABC");
tw.WriteEndElement();
tw.WriteEndElement();
tw.WriteElementString("Summary","Hi");
tw.WriteElementString("Text","Hello");

tw.WriteEndElement();
//tw.WriteEndDocument();
tw.Flush();
tw.Close();

StreamReader srXml = new StreamReader(filename);
string xmlFile = srXml.ReadToEnd();



}



Regards
Anil Pandey

Thanks & Regards
Anil Kumar Pandey



Author: Natchatraa    24 Nov 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 6

Hi,
private string CreateBookXML()
{
XmlDocument doc = new XmlDocument();
XmlDeclaration declaration= doc.CreateXmlDeclaration("1.0", "UTF8", "");
doc.AppendChild(declaration);
XmlElement rootElement=doc.CreateElement("Book");
doc.AppendChild(rootElement);
XmlElement childElement = doc.CreateElement("English","");
childElement.InnerText = "OliverTwist";

XmlElement childElement1 = doc.CreateElement("Chemistry", "");
childElement1.InnerText = "OrganicChemistry";
rootElement.AppendChild(childElement1);

return doc.InnerXml; //Returning XML file as string
}
private string EditBookXML(string strSigPassword)
{
string strXMLInfo = CreateBookXML();
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.InnerXml = strXMLInfo;
XmlNode xmlNode1 = xmlDocument.SelectSingleNode("//English");
xmlNode1.InnerText = "Truth";
XmlNode xmlNode2 = xmlDocument.SelectSingleNode("//Chemistry");
xmlNode2.InnerText = "InorganicCjemistry";
return strXMLInfo;//Returning Edited XML file as string
}



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Two Xml Files One Xslt
Previous : XML file updating issue.........?
Return to Discussion Forum
Post New Message
Category: XML

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use