编写XMLDom

//创建XML文档对象

XmlDocument doc = new XmlDocument();

//创建XML文档描述

            XmlDeclaration xmldec = doc.CreateXmlDeclaration("1.0", "utf-8", null);

                            //创建子节点

            XmlNode classes = doc.CreateNode(XmlNodeType.Element, "classes", null);

                            //创建根元素

            XmlElement class19 = doc.CreateElement("class");

            XmlText class19name = doc.CreateTextNode(".NET19班㨤");

                  

            XmlAttribute class19attr = doc.CreateAttribute("stuno");

            class19attr.Value = "001";

 

            class19.AppendChild(class19name);

            //class19.AppendChild(class19attr);

            class19.Attributes.Append(class19attr);

 

            classes.AppendChild(class19);

 

            doc.AppendChild(xmldec);

            doc.AppendChild(classes);

                            //保存为文件

            string fileName = Server.MapPath(@"~/XML/WriterClasses19.xml");

            doc.Save(fileName);

            Response.Write("文件已经生¦成¨¦");

posted @ 2013-04-16 23:51  幸福的娟娟  阅读(113)  评论(0编辑  收藏  举报