1 private void ReadXML()
2 {
3 string url = Server.MapPath("news.xml");//获得当前文件夹下的XML文件
4 StreamReader sRead = new StreamReader(url, System.Text.Encoding.GetEncoding("GB2312"));
5 //以一种特定的编码从字节流读取字符,必须要转化成GB2312读取才不能出乱码
6 XmlDataDocument datadoc = new XmlDataDocument();//操作XML文档
7 datadoc.DataSet.ReadXml(sRead);//将读取的字节流存到DataSet里面去
8 this.GridView1.DataSource = datadoc.DataSet.Tables[0].DefaultView;
9 this.GridView1.DataBind();
10 datadoc = null;//清空对XML数据的操作
11 sRead.Close();//关闭字节流的读取
12 }
请发表评论