/ Published in: C#
Expand |
Embed | Plain Text
string fileName = MapPath("file.xml"); XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); xmlDoc.AppendChild(dec); //root node XmlElement root = xmlDoc.CreateElement("root"); xmlDoc.AppendChild(root); //parent node XmlElement albumNode = xmlDoc.CreateElement("parent"); albumNode.SetAttribute("title", ""); albumNode.SetAttribute("description", ""); root.AppendChild(albumNode); //process child nodes XmlElement newNode; foreach (Something item in SomethingList) { newNode = xmlDoc.CreateElement("child"); newNode.SetAttribute("attr", item.Text); newNode.InnerText = "text"; albumNode.AppendChild(newNode); } //save the file xmlDoc.Save(fileName);
You need to login to post a comment.
