So, below I made a code which lists my 2 items in comboBox1 by its name(Selena and Maria) on load, and when I select one of those, lets say Maria, and click on button1, it populates my 3 textboxes with Maria’s name,usn and pawd attribute values, and it looks like:
Display name: Maria
Username: mary26
Password: d4e5r
and I am happy with that part of code, because it serves my purpose.
But I am struggling with part of code which I am trying to figure out.
I created a button2, and I would like that, when I change values of Display name, Username or Password textboxes, and I click save, that it saves to right location in xml file, to Maria, and does not save it to Selena or something else.
I have tried browsing for a week now, and multiple solutions, and I couldn’t find any.
att.xml:
<database>
<item name="Selena" usn="sele22" pawd="fed47a"></item>
<item name="Maria" usn="mary26" pawd="d4e5r"></item>
<database>
myproject:
private void Form3_Load(object sender, EventArgs e)
{
comboBox1.Items.Clear();
XmlTextReader reader = new XmlTextReader("att.xml");
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "item")
{
comboBox1.Items.Add(reader.GetAttribute("name"));
}
}
}
reader.Close();
}
private void button1_Click(object sender, EventArgs e)
{
string secit = comboBox1.SelectedItem as string;
XmlTextReader lola = new XmlTextReader("att.xml");
while (lola.Read())
{
if (lola.NodeType == XmlNodeType.Element)
{
string poop = lola.GetAttribute("name");
if (poop == secit)
{
string username = lola.GetAttribute("usn");
string password = lola.GetAttribute("pawd");
string dispname = lola.GetAttribute("name");
textBox1.Text = dispname;
textBox2.Text = username;
textBox3.Text = password;
}
}
}
lola.Close();
}
You can use XmlDocument like this: