The Xml file generated by DataSet. WriteXml (String) contains the XML declaration, while DataSet. WriteXml (Stream) does not write the Xml Declaration, that is, <? Xml version = "1.0" standalone = "yes"?>
Details:
When I was writing a data backup program in the blog Park, I wanted to use ds. writeXml (Response. outputStream) directly sends Xml data to the client. However, all Chinese characters in the Xml file obtained by the client are garbled. The difference between a garbled Xml file and a normal Xml file is that a line of Xml declaration is missing. Then, I changed the code and manually wrote the Xml declaration to solve the garbled problem. The Code is as follows:
XmlTextWriter writer = new XmlTextWriter (Response. OutputStream, Response. ContentEncoding );
Writer. Formatting = Formatting. Indented;
Writer. Indentation = 4;
Writer. IndentChar = '';
Writer. WriteStartDocument ();
Ds. WriteXml (writer );
Writer. Flush ();
Response. End ();
Writer. Close ();