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"));//保存文件
转载于:https://www.cnblogs.com/sunnysmile/archive/2009/06/19/1506617.html