XML: 1 aaa 2 bbb
Code
var doc = XDocument.Load (Server.MapPath(".") + "\\Questions.config");
var elements = from element in doc.Descendants("Question")
select new
{
Id = element.Element("Id").Value,
Text = element.Element("Text").Value,
Reserver = element.Element("Reserver") != null
};
StringBuilder builder = new StringBuilder();
foreach (var question in elements)
{
builder.AppendLine(question.Id + "-" + question.Text);
}
myTextBox.Text = builder.ToString();
how insert new Node 'Question' to XML File
It's unclear exactly what your question means, but the basic process of updating the XML file would be along the lines of:
doc.Save("file.xml")
or something similarIt's hard to be more precise than that without having more precise requirements. As an example though, if you wanted to prefix every
Text
node in the document with "Question x: " where x is the ID of the question, you might write something like:Or to change every "aaa" Text element to "kkk":
Are you trying to do something like this?
EDIT: If you want to update every question then you have to slightly modify the code above.
In this way you don't select the value anymore but the XElement instead, so you're able to modify the XML. Remember also to save the file using
XDocument.Save()
.