小工具xml生成记录

 private void button1_Click(object sender, EventArgs e)
        {
            string path = @"D:\java\res\drawable-mdpi";
            DirectoryInfo root = new DirectoryInfo(path);
            FileInfo[] files = root.GetFiles();
            List<String> temp = new List<string>();
            for (int i = 0; i < files.Length; i++)
            {
                string filename = files[i].Name.ToString();
                temp.Add(filename.Substring(0,filename.Length-7));
            }
            List<String>  xx=temp.Distinct().ToList();
            foreach (string x in xx)
            {
                getxml(x);
            }
        }
        private void getxml(string sname)
        {
            //创建XmlDocument对象
            XmlDocument xmlDoc = new XmlDocument();
            //XML的声明<?xml version="1.0" encoding="gb2312"?>
            XmlDeclaration xmlSM = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
            //追加xmldecl位置
            xmlDoc.AppendChild(xmlSM);
            //添加一个名为Gen的根节点
            XmlElement xml = xmlDoc.CreateElement("", "animation-list", "");
            xml.SetAttribute("xmlns:android", "http://schemas.android.com/apk/res/android");
            xml.SetAttribute("android:oneshot", "false");
            //追加Gen的根节点位置
            xmlDoc.AppendChild(xml);

            for (int i = 1; i < 22; i++)
            {
                //添加一个名为<Zi>的节点   
                XmlElement zi = xmlDoc.CreateElement("item");
                //为<Zi>节点的属性
                zi.SetAttribute("android:drawable", "@drawable/"+sname+"_"+String.Format("{0:D2}",i));
                zi.SetAttribute("android:duration", "@string/ani_time");
                xml.AppendChild(zi);

            }   
            xmlDoc.Save("D:/"+sname+".xml");
        }

猜你喜欢

转载自www.cnblogs.com/yidianfeng/p/10474575.html