zoukankan      html  css  js  c++  java
  • c# 创建XML文档

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Xml;
    namespace _02创建一个XML文档
    {
        class Program
        {
            static void Main(string[] args)
            {
                XmlDocument doc = new XmlDocument();
                XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
                doc.AppendChild(dec);
    
                XmlElement person = doc.CreateElement("Person");
                doc.AppendChild(person);
    
                XmlElement student1 = doc.CreateElement("Student");
                student1.SetAttribute("ID", "1");
                person.AppendChild(student1);
    
                XmlElement name1 = doc.CreateElement("Name");
                name1.InnerText = "刘德华";
                student1.AppendChild(name1);
    
                XmlElement age1 = doc.CreateElement("Age");
                age1.InnerText = "60";
                student1.AppendChild(age1);
    
                XmlElement gender1 = doc.CreateElement("Gender");
                gender1.InnerText = "";
                student1.AppendChild(gender1);
    
    
    
                XmlElement student2 = doc.CreateElement("Student");
                student2.SetAttribute("ID", "2");
                person.AppendChild(student2);
    
                XmlElement name2 = doc.CreateElement("Name");
                name2.InnerText = "张学友";
                student2.AppendChild(name2);
    
                XmlElement age2 = doc.CreateElement("Age");
                age2.InnerText = "60";
                student2.AppendChild(age2);
    
                XmlElement gender2 = doc.CreateElement("Gender");
                gender2.InnerText = "";
                student2.AppendChild(gender2);
    
    
    
    
                XmlElement student3 = doc.CreateElement("Student");
                student3.SetAttribute("ID", "3");
                person.AppendChild(student3);
    
                XmlElement name3 = doc.CreateElement("Name");
                name3.InnerText = "黎明";
                student3.AppendChild(name3);
    
                XmlElement age3 = doc.CreateElement("Age");
                age3.InnerText = "40";
                student3.AppendChild(age3);
    
                XmlElement gender3 = doc.CreateElement("Gender");
                gender3.InnerText = "";
                student3.AppendChild(gender3);
    
    
                doc.Save("person.xml");
                Console.WriteLine("保存成功");
                Console.ReadKey();
    
            }
        }
    }
  • 相关阅读:
    windy数
    微信授权网页登陆,oauth
    Win7/Win2008下IIS配置Asp网站启用父路径的设置方法(已解决)
    Html5学习笔记1 元素 标签 属性
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'user'
    POJ 3978(求素数)
    java内存模型(Java Memory Model)
    【Unity3D自学记录】Unity3D之自制小钟表
    HDU4126Genghis Khan the Conqueror(最小生成树+并查集)
    gcc学习(一)[第二版]
  • 原文地址:https://www.cnblogs.com/suanshun/p/7001647.html
Copyright © 2011-2022 走看看