kleptos
Apr 5th, 2003, 04:45 PM
Below is code i have to write an a node to an xml file. How can i add an attribute to the "error" node?
XmlDocument doc = new XmlDocument();
doc.Load("Errors.xml");
XmlNode node = doc.CreateNode(XmlNodeType.Element,"error",null);
XmlNode item = doc.CreateNode(XmlNodeType.Element,"date",null);
item.InnerText = DateTime.Now.ToString();
doc.DocumentElement.AppendChild(node);
node.AppendChild(item);
doc.Save("Errors.xml");
The above gives me this:
<error>
<date>4/5/2003</date>
</error>
I want this:
<error id="14">
<date>4/5/2003</date>
</error>
XmlDocument doc = new XmlDocument();
doc.Load("Errors.xml");
XmlNode node = doc.CreateNode(XmlNodeType.Element,"error",null);
XmlNode item = doc.CreateNode(XmlNodeType.Element,"date",null);
item.InnerText = DateTime.Now.ToString();
doc.DocumentElement.AppendChild(node);
node.AppendChild(item);
doc.Save("Errors.xml");
The above gives me this:
<error>
<date>4/5/2003</date>
</error>
I want this:
<error id="14">
<date>4/5/2003</date>
</error>