Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

XML: how to fix XML format problem?

$
0
0

 We have export a file as XML format and  code are the same as following link (http://msdn.microsoft.com/en-us/library/ms162588(v=vs.100).aspx

Stream aStream = File.Create("afile.xml");
XmlTextWriter writer = new XmlTextWriter(aStream, System.Text.Encoding.Unicode);
writer.WriteStartDocument();
writer.WriteStartElement("Root");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
The result should be:<?xml version="1.0" encoding="utf-16"?><Root />

When we use NotePad++ (Plugins->XML Tools->Check XML Syntac Now) to check exported XML file format and we get the following:

"XML Parsing error at line1:

Document labelled UTF-16 but has UTF-8 content."

Does above code has any problem? Could we change any pc setting to fix the problem?

we know that if we change the following line it will work for UTF-8 encoding. However, this fix involve application code change. We prefer to through PC settings to fix this problem if we can.

XmlTextWriter writer = new XmlTextWriter(aStream, System.Text.Encoding.UTF8);

If we need to use "UTF-16", what code we should change? Thx


JaneC



Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>