I have a listbox and a textbox in my WPF. Im saving these values into an xml like this:
private void textBox1_LostFocus(object sender, RoutedEventArgs e)
{
if (listBox1.SelectedValue != null)
{
writer.WriteStartElement("Attribute",textBox1.Text);
ListBoxItem a = listBox1.SelectedValue as ListBoxItem;
if (a != null)
{
writer.WriteAttributeString("Name", a.Content.ToString());
}
//writer.WriteAttributeString("Value", textBox1.Text);
writer.WriteEndElement();
writer.Flush();
}
}
But when I select an item that is already selected and saved, i want my xml to be re-written. Now i get something like this:
<?xml version="1.0" encoding="utf-8"?>
<Query_advanced>
<Query>
<Attribute Name="Patient Name" xmlns="John" />
<Attribute Name="Patient Age" xmlns="23" />
<Attribute Name="Patient ID" xmlns="12" />
<Attribute Name="Patient Name" xmlns="Mary" />
</Query>
</Query_advanced>
How can I go about this? Thanks!
Taking @bitbonk’s answer answer into account and modifying, this worked for me: