1
I need to create an XML, but when I try to create 2 error elements, how do I generate 1 XML with two elements? follows my code
class Program
{
static void Main(string[] args)
{
using (XmlWriter writer = XmlWriter.Create("books.xml"))
{
writer.WriteStartElement("book");
writer.WriteElementString("title", "Graphics Programming using GDI+");
writer.WriteElementString("author", "Mahesh Chand");
writer.WriteElementString("publisher", "Addison-Wesley");
writer.WriteElementString("price", "64.95");
writer.WriteEndElement();
writer.WriteStartElement("newBook");
writer.WriteElementString("title", "Graphics Programming using GDI+");
writer.WriteElementString("author", "Mahesh Chand");
writer.WriteElementString("publisher", "Addison-Wesley");
writer.WriteElementString("price", "64.95");
writer.WriteEndElement();
writer.Flush();
}
}
}
Error code:
System.Invalidoperationexception: 'Token Startelement in state Endrootelement would result in an invalid XML Document. Make sure that the Conformancelevel Setting is set to Conformancelevel.Fragment or Conformancelevel.Auto if you want to write an XML Fragment. '
Check out this link for some examples of how to do http://www.macoratti.net/12/09/xml_cur2.htm
– Diego Farias