c#使用linq技術(shù)創(chuàng)建xml文件的小例子
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";
//創(chuàng)建XML文件
private void button1_Click(object sender, EventArgs e)
{
XDocument doc = new XDocument(//創(chuàng)建XML文檔對(duì)象
new XDeclaration("1.0", "utf-8", "yes"),//添加XML文件聲明
new XElement(textBox1.Text,//創(chuàng)建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文件創(chuàng)建成功");
}
}
}
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<Peoples> -<People ID="001"> <Name>123</Name> <Sex>123</Sex> <Salary>123</Salary> </People> </Peoples>
- C#中Linq查詢基本操作使用實(shí)例
- C# linq查詢之動(dòng)態(tài)OrderBy用法實(shí)例
- C#中的Linq Intersect與Except方法使用實(shí)例
- C#使用linq對(duì)數(shù)組進(jìn)行篩選排序的方法
- C#使用linq語(yǔ)句查詢數(shù)組中以特定字符開頭元素的方法
- C#使用linq查詢大數(shù)據(jù)集的方法
- C#使用LINQ查詢表達(dá)式的基本子句總結(jié)
- C# LINQ to XML應(yīng)用介紹
- C#程序中使用LINQ to XML來(lái)查詢XML格式數(shù)據(jù)的實(shí)例
- c#中LINQ的基本用法實(shí)例
相關(guān)文章
C#設(shè)計(jì)模式之適配器模式與裝飾器模式的實(shí)現(xiàn)
創(chuàng)建型設(shè)計(jì)模式主要是為了解決創(chuàng)建對(duì)象的問題,而結(jié)構(gòu)型設(shè)計(jì)模式則是為了解決已有對(duì)象的使用問題。本文將用C#語(yǔ)言實(shí)現(xiàn)結(jié)構(gòu)型設(shè)計(jì)模式中的適配器模式與裝飾器模式,感興趣的可以了解一下2022-04-04
C# 并發(fā)控制框架之單線程環(huán)境下實(shí)現(xiàn)每秒百萬(wàn)級(jí)調(diào)度
本文介紹了一款專為工業(yè)自動(dòng)化及機(jī)器視覺開發(fā)的C#并發(fā)流程控制框架,通過模仿Go語(yǔ)言并發(fā)模式設(shè)計(jì),支持高頻調(diào)度及復(fù)雜任務(wù)處理,已在多個(gè)項(xiàng)目中驗(yàn)證其穩(wěn)定性和可靠性2024-10-10
C#文件斷點(diǎn)續(xù)傳實(shí)現(xiàn)方法
C#實(shí)現(xiàn)利用反射簡(jiǎn)化給類字段賦值的方法
C#使用Dynamic實(shí)現(xiàn)簡(jiǎn)化反射
c# WPF實(shí)現(xiàn)Windows資源管理器(附源碼)

