• 小工具xml生成记录


    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                string path = @"D:java esdrawable-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);
                    sssss(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");
            }

            private void button2_Click(object sender, EventArgs e)
            {

            }
            private void sssss(string sname)
            {
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:/" + sname + ".xml", true))
                {
                    file.WriteLine("<?xml version="1.0" encoding="utf-8"?>");// 直接追加文件末尾,换行
                    file.WriteLine("<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">");
                    for (int i = 1; i < 22; i++)
                    {
                        file.WriteLine(" <item android:drawable="@drawable/" + sname + "_" + String.Format("{0:D2}", i) + "" android:duration="@string/ani_time"/>");
                    }
                    file.WriteLine("</animation-list>");



                }
            }
        }

  • 相关阅读:
    Source Insight 安装使用
    size_t和ssize_t
    jquery ui autoComplete自动完成
    一个php类 Autoloader
    php register_shutdown_function
    mysql concat和group_concat
    nginx反向代理
    6.关于QT中的内存管理,动态的制作,动态库的调用,静态库的制作
    Sublime Text2 按shift键选择不了的问题
    javascript--瀑布流
  • 原文地址:https://www.cnblogs.com/yidianfeng/p/10474575.html
Copyright © 2020-2023  润新知