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>