So... I have 2 textboxes and 1 button. And when I input data to those textboxes, and click the button, I would like it to enter xml file and add new element with attributes to it, without replacing it. After a lot of browsing I managed to do something that replaced all text in my xml file, or I got an error, so I decided to post a question here.
So this is how my xml file looks:
<library>
<book name="Her way" price="20"></book>
<book name="His way" price="20"></book>
</library>
and what I'm trying to do is to insert:
<book name="Their way" price="22"></book>
bellow last one so it would look like:
<library>
<book name="Her way" price="20"></book>
<book name="His way" price="20"></book>
<book name="Their way" price="22"></book>
</library>
And every time I click button again, it adds it same way, ofc I would change name and price in textbox.
I came up with this code, but I am fairly new to xml so I don't know how to modify it or make it work.
XDocument doc = XDocument.Load("booklibrary.xml");
doc.Add(new XElement("book",
new XAttribute("name", textBox1.Text),
new XAttribute("price", textBox3.Text)));
doc.Save("booklibrary.xml");
Thank you!