日期:2014-05-18 浏览次数:20462 次
            DataTable dt = new DataTable();
            dt.Columns.Add("filename");
            dt.Columns.Add("phototitle");
            dt.Rows.Add(new object[] { "./img/img04.jpg", "www.sharejs.com - 图片4" });
            dt.Rows.Add(new object[] { "./img/img05.jpg", "www.sharejs.com - 图片5" });
            XmlDocument xml = new XmlDocument();
            XmlDeclaration declar = xml.CreateXmlDeclaration("1.0", "utf-8", null);
            xml.AppendChild(declar);
            XmlNode root = xml.CreateElement("root");
            xml.AppendChild(root);
            foreach (DataRow r in dt.Rows)
            {
                XmlNode photo = xml.CreateElement("photo");
                XmlNode filename = xml.CreateElement("filename");
                filename.InnerText = r["filename"].ToString();
                XmlNode phototitle = xml.CreateElement("phototitle");
                phototitle.InnerText = r["phototitle"].ToString();
                photo.AppendChild(filename);
                photo.AppendChild(phototitle);
                root.AppendChild(photo);
            }
            xml.Save(@"E:\1.xml");