using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
namespace QueryXMLByLINQ
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
static string strPath = "";
static string strID = "";
//Load XML file when the form is loaded
private void Form1_Load(object sender, EventArgs e)
{
getXmlInfo();
}
//Show detailed information of the selected XML node
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
strID = [].Cells[3].();//Record the selected employee number
XElement xe = (strPath);//Load XML file
//Use LINT to query information from XML files
IEnumerable<XElement> elements = from PInfo in ("People")
where ("ID").Value == strID
select PInfo;
foreach (XElement element in elements)//Travel the query results
{
= ("Name").Value;//Show employee name
= ("Sex").Value;//Show employee gender
= ("Salary").Value;//Show employee salary
}
}
#region Bind XML file content to DataGridView control
/// <summary>
///Bind XML file content to DataGridView control
/// </summary>
private void getXmlInfo()
{
DataSet myds = new DataSet();
(strPath);
= [0];
}
#endregion
}
}