zoukankan      html  css  js  c++  java
  • C#读写XML的演示程序(1)

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Xml;

    namespace 读写xml测试
    {
        public partial class Form1 : Form
        {
            String xmlPath = Application.StartupPath + "\\demo.xml";
            XmlElement xmlroot;
            XmlDocument xmldoc = new XmlDocument();
            public Form1()
            {
                InitializeComponent();
            }

            ******* void button1_Click(object sender, EventArgs e)
            {
                //添加xml的根节点
                xmlroot = xmldoc.CreateElement(textBox1.Text);
                xmldoc.AppendChild(xmlroot);
                xmldoc.Save(xmlPath);
            }

            ******* void button2_Click(object sender, EventArgs e)
            {
                //添加xml的子节点
                XmlElement xmlchild1 = xmldoc.CreateElement(textBox2.Text);
                xmlchild1.InnerText = "红色";
                xmlroot.AppendChild(xmlchild1);

                xmldoc.Save(xmlPath);
            }

            ******* void button3_Click(object sender, EventArgs e)
            {
                //遍历显示
                String str1 = null;
                XmlDocument myxml = new XmlDocument();
                myxml.Load(xmlPath);
                XmlNode rootnode = myxml.DocumentElement;
                foreach (XmlNode m in rootnode.ChildNodes)
                {
                    str1 += m.Name;
                    str1 += ":";
                    str1 += m.InnerText;
                    str1 += Environment.NewLine;

                }
                richTextBox1.Text = str1;
            }
        }
    }
     

    源代码下载

  • 相关阅读:
    [GUIDE] How to Setup Ubuntu 16.04 LTS Xenial Xerus for Compiling Android ROMs
    设置Ubuntu 16.04 LTS的Unity启动器的位置命令
    sed系列:行或者模式匹配删除特定行
    HDOJ 4923 Room and Moor
    Office365client通过本地方式批量部署(即点即用部署)
    hdu 1867 A + B for you again
    Photoshop经常使用快捷键(2)
    SQL_为表和列加凝视
    从头认识java-17.5 堵塞队列(以生产者消费者模式为例)
    Unity5 怎样做资源管理和增量更新
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668491.html
Copyright © 2011-2022 走看看