I am writing a Xml file, however I have a while loop that asks the user to insert some data. The problem I am having is that when the user closes the command prompt box ( to input the data) the root node doesn't close itself.
How can I close the root node "People" when the user exits?
thanks
** I am using c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Text;
namespace XML
{
class Program
{
static void Main(string[] args)
{
XmlTextWriter writer = new XmlTextWriter("C:\\Users\\gghossei\\Desktop\\XmlTestDoc.xml", Encoding.UTF8);
writer.Formatting = Formatting.Indented;
// root
writer.WriteStartElement("People");
writer.Flush();
bool done = false;
while (!done)
{
string message;
Console.WriteLine("Please enter your message:");
message = Console.ReadLine();
writer.WriteElementString("Something", message);
writer.Flush();
}
writer.WriteEndElement();
}
}
the problem is when you close this while loop by pressing x on the command prompt it doesn't close the root node "People"...