林林菜园
www.code84.com
 XmlDataDocument xd = new XmlDataDocument();//创建xml文件
           XmlDeclaration xde = xd.CreateXmlDeclaration("1.0", "gb2312", null);//版本
           xd.AppendChild(xde);
           XmlElement xe = xd.CreateElement("viewer");//创建节点
           xe.SetAttribute("interval","4000");//设置属性
            xe.SetAttribute("isRandom","1");
            xd.AppendChild(xe);
            XmlNode viewer = xd.SelectSingleNode("viewer");
            foreach (DataRow dr in dsslide.Tables[0].Rows)//循环表
            {
                XmlElement xe1 = xd.CreateElement("item");
                xe1.SetAttribute("title", SN.Common.Utils.GetSubString(dr["title"].ToString(), 20, "..."));
                xe1.SetAttribute("img", dr["path"].ToString());
                xe1.SetAttribute("url", "/terrace/research/details.aspx?id=" + dr["aid"].ToString());
                xe1.SetAttribute("target", "_blank");
                viewer.AppendChild(xe1);
            }
            xd.Save(Server.MapPath("xml.xml"));//保存文件
posted on 2009-06-19 11:17  林林菜园  阅读(210)  评论(0编辑  收藏  举报