2
Reply

How to write / append XML to a File

kcanil

kcanil

May 24 2005 7:52 PM
8k
Hello guys...I'm writing an Exception logging block which will save the Exceptions to the XML file and appends each exception...I'm stuck at appending the Exception to the file...The sameple data looks like this (There is a lot of other information, but am not posting it because of space constraints.... The File looks like.... When another exception arises, i will get a XmlDocument which will have similar data....For ex... When i append the second exception information to the file, it shud look like I'm tryiong to do some thing like below.. Note: The below code may not work ..but this is some thing similar to what i'm doing... void Write(XmlDocument ExceptionInfo, NameValueCollection ConfigSettings) { string filename = ConfigSettings["fileName"]; XmlDocument expDoc = new XmlDocument(); XmlDocument xmlDoc = new XmlDocument(); XmlNode xmlNode; expDoc.LoadXml(ExceptionInfo.OuterXml); xmlNode = expDoc.FirstChild; xmlDoc.Load(filename); xmlDoc.FirstChild.AppendChild(xmlNode); } But am not able to make changes to the file... When i'm trying to play wiht the code, I'm getting some runtime errors..Can someone point me in the right direction? Thanks.

Answers (2)