动态写XML文件
因为子节点的个数不一样。所以用循环写
可是添加节点的时候又不能重复添加相同节点
XmlDocument doc = new XmlDocument(); // 创建dom对象 XmlElement root = doc.CreateElement("ADConfig"); // 创建根节点
for (int x = 0; x < list.Count; x++)
{
XmlElement ch = doc.CreateElement("AD");
ch.SetAttribute("Id", x.ToString());
ch.SetAttribute("Image", "Images/PPT/DF6/" + list[x]);
ch.SetAttribute("Title", "");
ch.SetAttribute("Description", "");
doc.AppendChild(ch);
}
因为子节点的个数不一样。所以用循环写
可是添加节点的时候又不能重复添加相同节点
XmlDocument doc = new XmlDocument(); // 创建dom对象 XmlElement root = doc.CreateElement("ADConfig"); // 创建根节点
for (int x = 0; x < list.Count; x++)
{
XmlElement ch = doc.CreateElement("AD");
ch.SetAttribute("Id", x.ToString());
ch.SetAttribute("Image", "Images/PPT/DF6/" + list[x]);
ch.SetAttribute("Title", "");
ch.SetAttribute("Description", "");
doc.AppendChild(ch);
}
XML跟节点只能有一个你应该是想
root.AppendChild(ch);
doc.AppenChild(root);