動態(tài)生成xml內(nèi)容,顯示到頁面上,在ie中查看,無法顯示xml頁,提示內(nèi)容應該是編碼有問題,不知道怎么解決???????
代碼大概如下
?XmlDocument xmldoc = new XmlDocument();
????????? //聲明??????????? XmlDeclaration xmldecl;??????????? xmldecl = xmldoc.CreateXmlDeclaration("1.0", "UTF-8", null); ;??????????? xmldecl.Encoding = "GB2312";?????????????????
???????????? //加入一個根元素??????????? XmlElement xmlelem = xmldoc.CreateElement("", "YFBGLIST", "");??????????? xmldoc.AppendChild(xmlelem);??????????? xmldoc.InsertBefore(xmldecl, xmlelem);??????? ??????? ????????? //加入另外一個元素??????????? for (int i = 0; i < rsint; i )??????????? {??????????????? string[] k = new string[k2];??????????????? k = rs[i].Split('@');??????????????? XmlNode root = xmldoc.SelectSingleNode("YFBGLIST");//查找<Employees>??????????????? XmlElement xe1 = xmldoc.CreateElement("YFBG");//創(chuàng)建一個<Node>節(jié)點??????????????????? XmlElement xesub1 = xmldoc.CreateElement("yfbgtitle");??????????????? xesub1.InnerText = k[0];
??????????????? xe1.AppendChild(xesub1);//添加到<Node>節(jié)點中??????????????? XmlElement xesub2 = xmldoc.CreateElement("researcher");??????????????? xesub2.InnerText = k[3];??????????????? xe1.AppendChild(xesub2);??????????????? XmlElement xesub3 = xmldoc.CreateElement("url");??????????????? xesub3.InnerText =? k[4];??????????????? XmlElement xesub4 = xmldoc.CreateElement("content");??????????????? xesub4.InnerText = k[5];??????????????? xe1.AppendChild(xesub3);
??????????????? root.AppendChild(xe1);// ??????????? }???????????????????? MemoryStream stream = new MemoryStream();??????????? XmlTextWriter writer = new XmlTextWriter(stream, new? System.Text.UTF8Encoding(false));??????????? writer.Formatting = Formatting.Indented;
??????????? xmldoc.Save(writer);
??????????? StreamReader sr = new StreamReader(stream, new System.Text.UTF8Encoding(false));??????????? stream.Position = 0;??????????? string XMLString = sr.ReadToEnd();??????????? return XMLString;
??????????? sr.Close();??????????? stream.Close();
- 4 回答
- 0 關注
- 437 瀏覽
添加回答
舉報
0/150
提交
取消