Token startelement in state epilog would result in an invalid xml document.
I was creating an XML document and kept running into this same error over and over again. It seems that it is the default error for any sort of syntax problem with your XML documents. So I would venture to guess that there are lots of ways of fixing it, but what worked for me was pretty simple (as most syntax errors are). I didn't have a root element. So make sure you always have a root or else!See below for my code for writing an XML Doc
string filepath = GetPath("myXML.xml"); //get full path
xmlTextWriter writer = new XmlTextWriter(filepath, null);
writer.WriteStartDocument();
writer.WriteStartElement("root"); //must have!!!!
foreach (Person p in myPeeps) {
writer.WriteStartElement("person");
writer.WriteStartElement("name");
writer.WriteString(p.Name);
writer.WriteEndElement();
writer.WriteStartElement("address");
writer.WriteString(p.address);
writer.WriteEndElement();
writer.WriteStartElement("title");
writer.WriteString(p.Title);
writer.WriteEndElement();
writer.WriteStartElement("age");
writer.WriteString(p.age);
writer.WriteEndElement();
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
Labels: .NET
posted by Tom Becker at
8/07/2009
![]()

0 Comments:
Post a Comment
<< Home