如何显示XML? [英] how to display XML?

查看:80
本文介绍了如何显示XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  WebRequest的REQ = HttpWebRequest.Create(http://example.com/example);
    WebResponse类解析度= req.GetResponse();
    StreamReader的SR =新的StreamReader(res.GetResponseStream());
    字符串str = sr.ReadToEnd();
    XmlDocument的DOC =新的XmlDocument();
    doc.LoadXml(STR);
    XmlTextWriter的作家=新的XmlTextWriter(D://myGameSite//myGames.xml,NULL);
    writer.Formatting = Formatting.Indented;
    doc.Save(作家); **强大的文本**
    的Response.Write(DOC);

现在这个code为正常使用我的意思是保存在文件命名myGames的myGameSite的根目录下的XML文件,但是当我尝试显示在浏览器这个XML文件,你可以在$看C $ C,它只是清楚地显示此

  System.Xml.XmlDocument

我要显示在我的浏览器与标签沿着这个XML文件,我的asp.net的版本和.netframework是2.0,所以请我不能使用LINQ:(


解决方案

这将做;)

 的Response.Write(< pre>< code基+ Server.HtmlEn code(doc.InnerXml)+< / code>< / pre>中);

修改

或者你可以在一个textarea显示XML

 < ASP:文本框ID =txtXml=服务器的TextMode =多行高度=500px的WIDTH =600px的/>

后面

code

  //这将preserve缩进
    txtXml.Text = doc.InnerXml;

    WebRequest req = HttpWebRequest.Create("http://example.com/example");
    WebResponse res = req.GetResponse();
    StreamReader sr = new StreamReader(res.GetResponseStream());
    string str = sr.ReadToEnd();
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(str);
    XmlTextWriter writer = new XmlTextWriter("D://myGameSite//myGames.xml", null);
    writer.Formatting = Formatting.Indented;
    doc.Save(writer);**strong text**
    Response.Write(doc);

now this code is working perfectly I mean it saves the XML file in the root directory of the myGameSite with the file named myGames, but when I try to display this XML file in browser as you can see in the code, it just plainly displays this

    System.Xml.XmlDocument

I want to display this XML file in my browser along with the tags, and the version of my asp.net and .netframework is 2.0 so please I can't use LINQ :(

解决方案

This will do ;)

Response.Write("<pre><code>" + Server.HtmlEncode(doc.InnerXml) + "</code></pre>");

EDIT

Or you can display the xml in a textarea

<asp:TextBox ID="txtXml" runat="server" TextMode="MultiLine" Height="500px" Width="600px" />

Code behind

// This will preserve indentation 
    txtXml.Text = doc.InnerXml;

这篇关于如何显示XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆