Csharp/C#教程:c#使用linq技术创建xml文件的小例子分享

代码如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.IO;
usingSystem.Xml;
usingSystem.Xml.Linq;

namespaceCreateXMLByLINQ
{
   publicpartialclassFrm_Main:Form
   {
       publicFrm_Main()
       {
           InitializeComponent();
       }

       staticstringstrPath=”Employee.xml”;

       //创建XML文件
       privatevoidbutton1_Click(objectsender,EventArgse)
       {
           XDocumentdoc=newXDocument(//创建XML文档对象
               newXDeclaration(“1.0″,”utf-8″,”yes”),//添加XML文件声明
               newXElement(textBox1.Text,//创建XML元素
                   newXElement(textBox2.Text,newXAttribute(textBox3.Text,textBox10.Text),//为XML元素添加属性
                       newXElement(textBox4.Text,textBox5.Text),
                       newXElement(textBox6.Text,textBox7.Text),
                       newXElement(textBox8.Text,textBox9.Text))
                   )
               );
           doc.Save(strPath);//保存XML文档
           MessageBox.Show(“XML文件创建成功”);
       }
   }
}

代码如下:

<?xmlversion=”1.0″encoding=”UTF-8″standalone=”true”?>
-<Peoples>-<PeopleID=”001″><Name>123</Name><Sex>123</Sex><Salary>123</Salary></People></Peoples>

上述就是C#学习教程:c#使用linq技术创建xml文件的小例子分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)! 您可能感兴趣的文章:C#中Linq查询基本操作使用实例C#linq查询之动态OrderBy用法实例C#中的LinqIntersect与Except方法使用实例C#使用linq对数组进行筛选排序的方法C#使用linq语句查询数组中以特定字符开头元素的方法C#使用linq查询大数据集的方法C#使用LINQ查询表达式的基本子句

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/904489.html

(0)
上一篇 2021年10月21日
下一篇 2021年10月21日

精彩推荐