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();
    
            }
        }
    }
  • 相关阅读:
    散户如何战胜专业投资机构
    机器学习总结
    进程线程及堆栈关系的总结
    线程堆栈是如何增长的
    Ubuntu下CodeBlocks控制台程序中文显示乱码解决问题
    jdk 安装
    python文件运行报错:Error: Please select a valid Python interpreter
    python 解释器安装
    allure在pycharm下运行出现以下乱码的提示 解决方案
    pytest 测试环境框架搭建
  • 原文地址:https://www.cnblogs.com/suanshun/p/7001647.html
Copyright © 2011-2022 走看看