using using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; System.Xml;

namespace Window_XML { public partial class Form1 : Form { public Form1() { InitializeComponent(); } XmlDocument doc = new XmlDocument(); //creating obj for xml document private void button1_Click(object sender, EventArgs e) { //XmlDocument doc = new XmlDocument(); doc.Load("Student.xml"); //MessageBox.Show(doc.OuterXml); //It will displays the Full XML Doc ument (Total document Student.xml) XmlElement elmstuds = doc.DocumentElement; //It will fetch only from root node (Starting from <Students>...</Students>) //MessageBox.Show(elmstuds.OuterXml); //It will display from root no de XmlElement elmstud = (XmlElement)elmstuds.ChildNodes[0]; //fetch the data of element node based on Index //MessageBox.Show(elmstud.OuterXml); //Displays the Element Node Dat a <Student>....</Student> XmlElement elmname = (XmlElement)elmstud.ChildNodes[0]; //fetch the data of child node of element node based on Index //MessageBox.Show(elmname.OuterXml); //Displays <Name>....</Name> XmlText elmtxt = (XmlText)elmname.FirstChild; //fetches the text of child node of element node based on Index //MessageBox.Show(elmtxt.OuterXml); //Displays Name of the student = "Student1" XmlAttribute elmroll = elmstud.GetAttributeNode("Rollno"); //fetches the attribute values of child node of element node based on Index //MessageBox.Show(elmroll.Value); //Displays the Rollno value as 100 //MessageBox.Show(elmroll.Value +" "+ elmstuds.ChildNodes[0].FirstCh ild.FirstChild.Value); } XmlElement elmstuds; private void Form1_Load(object sender, EventArgs e)

XmlElement elmstud = (XmlElement)elmstuds.Value.Save("Student. enres.FirstChild.ChildNodes[ind].SelectedIndex. comboBox1.xml").Text). tnname = doc. enstud = doc. elmstuds. XmlElement elmstud = (XmlElement)elmstuds.RemoveChild(elmstud).ParentNode. } private void comboBox1_SelectedIndexChanged(object sender.Items.Items.Text).xml"). elmstud.ChildNodes[ind].AppendChild(enstud).Load("Student.CreateAttribute("Rollno").Text.CreateTextNode(txtName. EventArgs e) { int ind = comboBox1.FirstChild. enstud. txtResult.Text). MessageBox. tnresult = doc. tnresult.FirstChild.{ doc.CreateElement("Student"). enres = doc.Value = txtName.Text = elmstud. comboBox1.Value = txtResult. } private void btnupdate_Click(object sender. XmlAttribute anid.SetAttributeNode(anid). EventArgs e) { XmlElement enstud.CreateTextNode(txtResult. .LastChild.Text.Add(elmstud.xml"). elmstud.FirstChild.xml"). enres. XmlElement elmstud = (XmlElement)elmstuds. doc. enname.ChildNodes) comboBox1.FirstChild.Items. EventArgs e) { int ind = comboBox1.FirstChild.DocumentElement.AppendChild(enres). enname.Show("New Node Added with ID: "+comboBox1. txtName. enstud.Text = elmstud.ChildNodes[ind].Save("Student.Save("Student. XmlText tnname. } private void btnSubmit_Click(object sender. EventArgs e) { int ind = comboBox1.GetAttributeNode("Rollno")).SelectedIndex. } private void btndelete_Click(object sender. enstud.AppendChild(tnname).Remove(comboBox1.CreateElement("Name"). elmstud. enname = doc.Add(comboBox1.Text).AppendChild(tnresult).Text). doc. elmstuds = doc. foreach (XmlElement elmstud in elmstuds. doc.SelectedIndex.Value.AppendChild(enname).LastChild.CreateElement("Result"). anid = doc.

EventArgs e) { DataSet ds = new DataSet(). } } } .ReadXml("Student.} private void btndisp_Click(object sender.Tables[0].xml"). ds. dataGrd.DataSource = ds.

Sign up to vote on this title
UsefulNot useful