Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For Example I use only 2 child nodes (FirstName,LastName). and I took file.xml in same directory with exe file, here's the code : </p> <pre><code>using System; using System.Windows.Forms; using System.Xml; namespace UpdateXmlRecord { public partial class Form1 : Form { private XmlDocument xDoc; public Form1() { InitializeComponent(); xDoc = new XmlDocument(); xDoc.Load("file.xml"); } /// &lt;summary&gt; /// Retrieve Xml Node /// &lt;/summary&gt; /// &lt;param name="sender"&gt;&lt;/param&gt; /// &lt;param name="e"&gt;&lt;/param&gt; private void button1_Click(object sender, EventArgs e) { string id = txtId.Text; string fName = "", lName = ""; foreach (XmlElement element in xDoc.DocumentElement) { if (element.Name == "Customer" &amp;&amp; element.Attributes["id"].Value == id) { foreach (XmlNode node in element) { if (node.Name == "FirstName") { fName = node.InnerText; } if (node.Name == "LastName") { lName = node.InnerText; } } } } txtFName.Text = fName; txtLName.Text = lName; } /// &lt;summary&gt; /// Save Xml Node With Custom Value /// &lt;/summary&gt; /// &lt;param name="sender"&gt;&lt;/param&gt; /// &lt;param name="e"&gt;&lt;/param&gt; private void button2_Click(object sender, EventArgs e) { string id = txtId.Text; foreach (XmlElement element in xDoc.DocumentElement) { if (element.Name == "Customer" &amp;&amp; element.Attributes["id"].Value == id) { foreach (XmlNode node in element) { if (node.Name == "FirstName") { node.InnerText = txtFName.Text; } if (node.Name == "LastName") { node.InnerText = txtLName.Text; } } } } xDoc.Save("file.xml"); } } } </code></pre> <p>hope it's helpfull, enjoy it. :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload