qlzgdz1992
New Member
I'm trying to update the attributes of a xml. My problem is that when I update and later I read my xml I have an exception. I was looking for the problem and I don't know how but at the end of xml appears the last character of my general close tag. Sometimes the three or two characters last or only the character \[code\]>\[/code\]. This problem don't occur always. Sometimes in the second time, others in fourth time, other in tenth times... I put a snippet bellow. thanks so much and sorry for my English.PD: I don't use Linq\[code\]// I need open and close FileStream because I had problems beforeSystem.IO.FileStream fs = new System.IO.FileStream (path, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);XmlDocument doc = new XmlDocument ();doc = new XmlDocument ();doc.Load (fs);fs.Close ();XmlNode element = doc.DocumentElement;// Change Dateelement.ChildNodes[0].Attributes.GetNamedItem ("date").Value = http://stackoverflow.com/questions/13824600/DateTime.Now.ToString ("dd/MM/yy");// [...] Change other attributes in the same wayfs = new System.IO.FileStream (path, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);doc.Save (fs);fs.Close ();\[/code\]My XML\[code\]// At the end of xml file appears this fragment<?xml version="1.0"?><MYPRINCIPALTAG> <TAG DATE="01/01/01"></TAG></MYPRINCIPALTAG>AG>\[/code\]