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

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    
    namespace ConsoleDemo
    {
        class Programme
        {
            public static void Main(string[] args)
            {
                XmlDocument doc = new XmlDocument();
                XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", "no");
                doc.AppendChild(dec);
    
                XmlElement root=doc.CreateElement("info");
                doc.AppendChild(root);
    
                XmlElement stu = doc.CreateElement("student");
                stu.SetAttribute("id", "001");
                root.AppendChild(stu);
    
                XmlElement name = doc.CreateElement("name");
                name.InnerText = "小明";
                stu.AppendChild(name);
    
                doc.Save("info.xml");
            }
        }
    }

     结果

    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <info>
      <student id="001">
        <name>小明</name>
      </student>
    </info>
  • 相关阅读:
    7段数码管绘制
    画五角星
    绘制正方形
    蟒蛇的绘制
    玫瑰花
    小猪佩奇
    数列求和
    水仙花数
    鸡兔同笼
    画国际象棋盘
  • 原文地址:https://www.cnblogs.com/luckystar-67/p/3611454.html
Copyright © 2011-2022 走看看