在内存中创建XML和把UTF-8转成GB2312

留着备用。

MemoryStream ms = new MemoryStream(); XmlTextWriter XmlTextW = new XmlTextWriter(ms, System.Text.Encoding.UTF8); XmlTextW.Formatting = Formatting.Indented; XmlTextW.WriteStartDocument(true); XmlTextW.WriteStartElement("mms");//开始 XmlTextW.WriteAttributeString("title", "测试彩信");//属性 XmlTextW.WriteAttributeString("maxSize", "9");//属性 XmlTextW.WriteAttributeString("mmspath", "http://mms.haedu.cn/MMS_DATA/2011/4/15/103025/");//属性 XmlTextW.WriteAttributeString("mmsfile", "smil.xml");//属性 XmlTextW.WriteStartElement("phones"); XmlTextW.WriteString("13333333333"); XmlTextW.WriteEndElement(); XmlTextW.WriteEndDocument();//结束 XmlTextW.Close(); byte[] data = ms.ToArray(); string xmlmsg = System.Text.Encoding.UTF8.GetString(data); string a = "<?xml version=/"1.0/" encoding=/"gb2312/"?><mms><title>测试彩信</title><maxSize>9</maxSize><mmspath>http://mms.haedu.cn/MMS_DATA/2011/4/15/103025/</mmspath><mmsfile>smil.xml</mmsfile><phones>13333333333</phones></mms>"; Encoding utf8 = Encoding.UTF8; Encoding gb2312 = Encoding.GetEncoding("GB2312"); byte[] temp=utf8.GetBytes(a); byte[] temp1 = Encoding.Convert(utf8, gb2312, temp); string b = gb2312.GetString(temp1);

你可能感兴趣的:(xml,String,测试,byte,encoding)