Differences between dataset. writexml (string) and (Stream) in Asp.net
Source: Internet
Author: User
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:
Data backup in blog writing ProgramYou want 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 Code, Manually write 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 ();
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service