L
Lloyd Dupont
I'm trying to write XML and I am quite unsuccessful so far,
I have a very simple application with 1 button and one click handler like
that, does anyone know what's wrong with this few lines ?
//-----------------------------------
private void button1_Click(object sender, System.EventArgs e)
{
string file = "test.xml";
XmlTextWriter xtw = new XmlTextWriter(file, Encoding.UTF8);
try
{
xtw.WriteStartDocument();
xtw.WriteElementString("Name", "aName");
xtw.WriteStartElement("Data");
xtw.WriteElementString("Item", "anItem");
xtw.WriteElementString("Item", "anItem");
xtw.WriteElementString("Item", "anItem");
xtw.WriteEndElement();
xtw.WriteEndDocument();
}
finally { xtw.Close(); }
}
it throws an InvalidOperationExeption() when I try to
WriteStartElement("Data");
I have a very simple application with 1 button and one click handler like
that, does anyone know what's wrong with this few lines ?
//-----------------------------------
private void button1_Click(object sender, System.EventArgs e)
{
string file = "test.xml";
XmlTextWriter xtw = new XmlTextWriter(file, Encoding.UTF8);
try
{
xtw.WriteStartDocument();
xtw.WriteElementString("Name", "aName");
xtw.WriteStartElement("Data");
xtw.WriteElementString("Item", "anItem");
xtw.WriteElementString("Item", "anItem");
xtw.WriteElementString("Item", "anItem");
xtw.WriteEndElement();
xtw.WriteEndDocument();
}
finally { xtw.Close(); }
}
it throws an InvalidOperationExeption() when I try to
WriteStartElement("Data");