I have a XML file which I want to update. The XML code is as follows:
Now I have a Windows application with all the fields as on XML file. I have tried using XmlTextWriter but I was not successful. I want to search for the node Name and add a new
the Date block every day.
Now can any one help me how to go about it.
SridharPosted Aug 1, 2006, 11:27 PM
Bhakeeswaran ThulasingamPosted Aug 1, 2006, 12:45 PM
Hi,
new XmlDocument();This method performs your required operation. Validate for null values in the below code and you can use it as it is.
Here the sName parameter takes the ID name node.
private void UpdateXML(String sName )
{
XmlDocument xmld =
xmld.Load("..\\WeeklyReport.xml");
XmlElement xmle = xmld.DocumentElement;
XmlNode xmln = xmle.SelectSingleNode("/WeeklyReport/Name[@ID='"+sName+"']");
XmlNode xmln2 = xmln.ChildNodes.Item(0);
XmlNode xmln3 = xmln2.CloneNode(true);
xmln3.SelectSingleNode("/TodaysDate").InnerText = System.DateTime.Now.Date.ToShortDateString();
xmln3.SelectSingleNode("/Assigned").InnerText = "True";
xmln3.SelectSingleNode("/Worked").InnerText = "True";
xmln3.SelectSingleNode("/ResolvedwithinSLA").InnerText = "True";
xmln3.SelectSingleNode("/Resolved").InnerText = "True";
xmln3.SelectSingleNode("/NotRelatedToAccess").InnerText = "True";
xmln.AppendChild(xmln3);
xmld.Save("..\\WeeklyReport.xml");
}
Hope this helps.
StuartPosted Aug 1, 2006, 11:34 AM
Try something along these lines
System.Xml.XmlDocument xmlDoc =
new System.Xml.XmlDocument();xmlDoc.Load(sXMLPath);
XmlNode xmlTopNode = xmlDoc.DocumentElement;
xmlElem = xmlDoc.CreateElement("Date");
xmlTopNode.AppendChild(NewElement(xmlElem (Cant remember syntax)
));It should get you on your way if nothing else.
Stu