zoukankan      html  css  js  c++  java
  • 小工具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>");



                }
            }
        }

  • 相关阅读:
    C# winIO32位,64位的使用(运行时要用管理员身份)
    C#实现的三种方式实现模拟键盘按键
    C#打印日志的小技巧
    write wall ping ifconfig mail last traceroute netstat setup mount
    安装常用工具 zip unzip bzip2 gcc gcc++编译器 cmake编译器
    gzip/gunzip tar -zcf/-zxvf zip /unzip bzip2/bunzip2 tar -cjf/tar -xjf
    help
    Asp.Net 高性能框架 SqlSugar.ORM 2.3
    centos 查看版本(转)
    浅谈OCR之Tesseract
  • 原文地址:https://www.cnblogs.com/yidianfeng/p/10474575.html
Copyright © 2011-2022 走看看