c\#linq 기술 로 xml 파일 을 만 드 는 작은 예

1738 단어 linqxml

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>

좋은 웹페이지 즐겨찾기