国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

c#使用linq技術創建xml文件的小例子

2020-01-24 03:31:20
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

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.IO;
using System.Xml;
using System.Xml.Linq;

namespace CreateXMLByLINQ
{
    public partial class Frm_Main : Form
    {
        public Frm_Main()
        {
            InitializeComponent();
        }

        static string strPath = "Employee.xml";

        //創建XML文件
        private void button1_Click(object sender, EventArgs e)
        {
            XDocument doc = new XDocument(//創建XML文檔對象
                new XDeclaration("1.0", "utf-8", "yes"),//添加XML文件聲明
                new XElement(textBox1.Text,//創建XML元素
                    new XElement(textBox2.Text, new XAttribute(textBox3.Text, textBox10.Text),//為XML元素添加屬性
                        new XElement(textBox4.Text, textBox5.Text),
                        new XElement(textBox6.Text, textBox7.Text),
                        new XElement(textBox8.Text, textBox9.Text))
                    )
                );
            doc.Save(strPath);//保存XML文檔
            MessageBox.Show("XML文件創建成功");
        }
    }
}

復制代碼 代碼如下:

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<Peoples> -<People ID="001"> <Name>123</Name> <Sex>123</Sex> <Salary>123</Salary> </People> </Peoples>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 商城县| 伊吾县| 奉节县| 裕民县| 农安县| 维西| 包头市| 长兴县| 龙山县| 牙克石市| 大悟县| 东乌珠穆沁旗| 那曲县| 庆阳市| 阳原县| 牡丹江市| 五常市| 崇礼县| 成武县| 澎湖县| 上杭县| 汽车| 杭州市| 长寿区| 长岛县| 淅川县| 邮箱| 城市| 沙湾县| 彰化市| 大埔区| 桃源县| 福贡县| 夏河县| 馆陶县| 甘孜| 庆城县| 金沙县| 团风县| 余江县| 禄劝|