I want to know the reason behind the XmlWriter.WriteStartDocument()
and XmlWriter.WriteEndDocument()
.
In my scenario I am creating an XML document with some data in it, e.g:
XmlWriter xmlWriter = XmlWriter.Create(file);
xmlWriter.WriteStartDocument();
// write xml elements and attributes...
xmlWriter.WriteEndDocument();
xmlWriter.Flush();
While serializing, XmlWriter
does not throw any exception if we skip the call to xmlWriter.WriteStartDocument()
and just call xmlWriter.WriteEndDocument()
at the end.
The below code snippet does not throw any error or exception:
XmlWriter xmlWriter = XmlWriter.Create(file);
// write xml elements and attributes...
xmlWriter.WriteEndDocument();
xmlWriter.Flush();
How is this possible? And can you explain the functionality of WriteStartDocument()
and WriteEndDocument()
?