asp.net the difference between dataset.writexml (String) and (Stream) _ Practical Tips

Source: Internet
Author: User
The XML file generated by DataSet.WriteXml (String) contains an XML declaration, while DataSet.WriteXml (Stream) does not write to the XML declaration, which is <?xml version= "1.0" Yes "?>
Detailed information:
When writing a data backup program for a blog park, you would have wanted to pass the DS. WriteXml (Response.outputstream) directly to the XML data sent to the client, but this in the client-made XML file in all Chinese is garbled, garbled XML file and normal XML file is less than a row of XML declaration. Then, I changed the code, manual write XML declaration, garbled problem is resolved, 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 ();
Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.