I am trying to update a simple xml file with XDocument. here is my simple xml file
<?xml version="1.0" encoding="utf-8" ?>
<message>Test test test test</message>
thats xml above.
when the user clicks the Button1, it reads the xml and display it on the screen. But when u click the Button2, it doesnt update the xml.
public partial class www_html_test : System.Web.UI.Page
{
XDocument doc;
XElement elem;
protected void Page_Load(object sender, EventArgs e)
{
doc = XDocument.Load(Server.MapPath("xml/test.xml"));
elem = doc.Element("message");
}
protected void Button1_Click(object sender, EventArgs e)
{
try{
Label1.Text = elem.Value.ToString();
} catch(Exception ex){
Label1.Text = ex.Message;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
try{
elem.Value = "test 2 test 2 test 2";
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
}
How can I update the xml?