If your operating system is a Chinese system,
1. You create an XML document. The default value is gb2312.
<? XML version = "1.0" encoding = "gb2312"?> You can definitely display Chinese characters.
2, you are changing someone else's XML document, but before the XML document is UTF-8/16 encoding,
<? XML version = "1.0" encoding = "gb2312"?>
Cannot display Chinese, because this document is not gb2312 encoding, although you force declare it to use gb2312 encoding conversion, but the gb2312 encoding mechanism can not handle the UTF-8/16 encoding. Must be converted using a UTF-8/16 encoding mechanism. That is
<? XML version = "1.0" encoding = "UTF-8"?> Or simply does not declare the encoding attribute.
PS: You can use the Save as function of the notepad that comes with windows to perform encoding and conversion.
Using system;
Using system. xml;
Class testxml
{
Public static void main ()
{
String sfile = "A. xml ";
Xmldocument Doc = new xmldocument ();
Doc. Load (sfile );
Xmlprocessinginstruction newpi;
String pitext = "type = 'text/XSL 'href = 'book. XSL '";
Newpi = Doc. createprocessinginstruction ("XML-stylesheet", pitext );
Doc. insertbefore (newpi, Doc. firstchild );
Xmltextwriter xtw = new xmltextwriter (sfile, system. Text. encoding. getencoding ("gb2312 "));
Xtw. Formatting = formatting. indented;
Xtw. writestartdocument ();
Doc. Save (xtw );
Xtw. writeenddocument ();
Xtw. Close ();
}
}