62,268
社区成员
发帖
与我相关
我的任务
分享
XmlNode root = xmlDoc.SelectSingleNode("bookstore");//查找<BOOKSTORE></BOOKSTORE>
XmlElement xe = xmlDoc.CreateElement("book");
xe.SetAttribute("genre", "jiyong");//设置节点属性
xe.SetAttribute("ISBN", "2-345-56");
XmlElement title = xmlDoc.CreateElement("title");
title.InnerText = "C#入门知识";//设置文本内容
xe.AppendChild(title);//添加节点
XmlElement author = xmlDoc.CreateElement("author");
author.InnerText = "jiyong";
xe.AppendChild(author);
XmlElement price = xmlDoc.CreateElement("price");
price.InnerText = "45.8";
xe.AppendChild(price);
root.AppendChild(xe);//加到根节点
xmlDoc.Save("C:\\bookstore.xml");
//给LZ一个生成XML文件的例子。。
XmlDocument xd = new XmlDocument();
//xd.CreateDocumentType("", "", "", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd");
XmlDeclaration xde;
xde = xd.CreateXmlDeclaration("1.0", "utf-8", "no");
xd.AppendChild(xde);
XmlElement xe = xd.CreateElement("Root");
xd.AppendChild(xe);
XmlElement node = xd.CreateElement("website");
node.SetAttribute("name", "Dtan网址导航");
node.SetAttribute("url", "http://www.dtan.so");
xe.AppendChild(node);
xd.Save(Server.MapPath("XML/website.config"));