C # small example of creating an xml file using the linq Technology

Source: Internet
Author: User

Copy codeThe Code is as follows: 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 ";

// Create an XML file
Private void button#click (object sender, EventArgs e)
{
XDocument doc = new XDocument (// create an XML Document Object
New XDeclaration ("1.0", "UTF-8", "yes"), // Add an XML file Declaration
New XElement (textBox1.Text, // create an XML Element
New XElement (textBox2.Text, new XAttribute (textBox3.Text, textBox10.Text), // Add attributes for XML elements
New XElement (textBox4.Text, textBox5.Text ),
New XElement (textBox6.Text, textBox7.Text ),
New XElement (textBox8.Text, textBox9.Text ))
)
);
Doc. Save (strPath); // Save the XML document
MessageBox. Show ("XML file created successfully ");
}
}
}

Copy codeThe Code is as follows:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.