c# xml文件添加3级子节点
XmlDocumentxmlDoc=newXmlDocument();xmlDoc.Load("Movies.xml");XmlNoderoot=xmlDoc.Selec...
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("Movies.xml");
XmlNode root = xmlDoc.SelectSingleNode("ShowList"); XmlElement element = xmlDoc.CreateElement("Movie");
XmlElement element2 = xmlDoc.CreateElement("Name"); element2.InnerText = txtName.Text; element.AppendChild(element2);
XmlElement element3 = xmlDoc.CreateElement("Poster"); element3.InnerText = picFileName; element.AppendChild(element3);
XmlElement element4 = xmlDoc.CreateElement("Director"); element4.InnerText = txtDaoyan.Text; element.AppendChild(element4);
XmlElement element5 = xmlDoc.CreateElement("Actor"); element5.InnerText = txtZhuyan.Text; element.AppendChild(element5);
XmlElement element6 = xmlDoc.CreateElement("Type"); element6.InnerText = cmbStyle.Text; element.AppendChild(element6);
XmlElement element7 = xmlDoc.CreateElement("Price"); element7.InnerText = txtPrice.Text; element.AppendChild(element7);
XmlElement element8 = xmlDoc.CreateElement("Schedule"); element8.InnerText = txtTime.Text;
element.AppendChild(element8);
root.AppendChild(element); xmlDoc.Save("Movies.xml");
如何在Schedule下增加子节点Item 达到如下效果 展开
XmlNode root = xmlDoc.SelectSingleNode("ShowList"); XmlElement element = xmlDoc.CreateElement("Movie");
XmlElement element2 = xmlDoc.CreateElement("Name"); element2.InnerText = txtName.Text; element.AppendChild(element2);
XmlElement element3 = xmlDoc.CreateElement("Poster"); element3.InnerText = picFileName; element.AppendChild(element3);
XmlElement element4 = xmlDoc.CreateElement("Director"); element4.InnerText = txtDaoyan.Text; element.AppendChild(element4);
XmlElement element5 = xmlDoc.CreateElement("Actor"); element5.InnerText = txtZhuyan.Text; element.AppendChild(element5);
XmlElement element6 = xmlDoc.CreateElement("Type"); element6.InnerText = cmbStyle.Text; element.AppendChild(element6);
XmlElement element7 = xmlDoc.CreateElement("Price"); element7.InnerText = txtPrice.Text; element.AppendChild(element7);
XmlElement element8 = xmlDoc.CreateElement("Schedule"); element8.InnerText = txtTime.Text;
element.AppendChild(element8);
root.AppendChild(element); xmlDoc.Save("Movies.xml");
如何在Schedule下增加子节点Item 达到如下效果 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询