Maybe a XmlTextWriter bug?

  • Thread starter Thread starter Diego Guidi
  • Start date Start date
D

Diego Guidi

I'm trying to do this:
XmlDocument document = new XmlDocument()
// document fill...
// Write a new xml file
WriteXmlDocument(document);

XmlDocument newDocument = new XmlDocument()
document.load(sameFileAsPrevious);
// fill document with other data
WriteXmlDocument(newDocument);

// Function that writes document in a file
WriteXmlDocument(XmlDocument document)
{
XmlTextWriter writer = new xmlTextWriter(filepath);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
document.write(writer);
}

The result is:
the first call to WriteXmlDocument generate a file correctly indented,
but the other calls to WriteXmlDocument generate all the new data (only
the new data, not the data written in the first pass) not indented!

Any suggestion?
 
Sorry but i have posted a simplified version of my code...
the real function WriteXmlDocument looks like this:
WriteXmlDocument(XmlDocument document)
{
XmlTextWriter writer = null;
try
{
writer = new XmlTextWriter(filepath, Encoding.UTF-8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
document.write(writer);
}
finally
{
if(writer != null) writer.Close();
}

}
 
Back
Top