ASP.NET页面上显示XML [英] Display XML on an ASP.NET page

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

问题描述

我有一个包含使用LinqtoXML XML文档的字符串

I have a string containing XML document using LinqtoXML

什么是asp.net页面上显示它看作是最好的方法。

What is the best way of displaying it on an asp.net page as is.

推荐答案

我也希望做到这一点使用丹尼斯提到的方式(一个< ASP:XML> 控制)。但是,必须使用一个XSL样式表来格式化的XML。 Xml控件不允许一个HTML连接codeD字符串作为DocumentContent财产通过,不公开c中的内容为en $ C $的任何方法。

I would have liked to do it the way Dennis has mentioned (using an <asp:Xml> control). But that necessitates the use of an XSL stylesheet to format the XML. The Xml control does not allow an HTML encoded string to be passed as the DocumentContent property and does not expose any method to encode the content.

正如我在评论丹尼斯后所提到的,包含MSXML.DLL内defaultss.xsl不可公开(而不是XSL 1.0标准)。然而,公众改装版本张贴在这里:<一href=\"http://www.dpawson.co.uk/xsl/sect2/microsoft.html#d7615e227\">http://www.dpawson.co.uk/xsl/sect2/microsoft.html#d7615e227.我已经测试它和它的作品,虽然有点马车。

As I have mentioned in the comments to Dennis' post, the defaultss.xsl contained within msxml.dll is not available publicly (and is not XSL 1.0 compliant). However, a public converted version was posted here: http://www.dpawson.co.uk/xsl/sect2/microsoft.html#d7615e227. I have tested it and it works, though a bit buggy.

因此​​,我认为最简单的方法是使用一个&LT; ASP:文字&GT; 控件输出pre-CN codeD XML的页。下面的示例演示此方法:

Therefore, I think the simplest way would be to use an <asp:Literal> control to output pre-encoded XML to the page. The following sample demonstrates this method:


<%@ Page Language="C#" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>

<script runat="server">
  protected void Page_Load(object sender, EventArgs e)
  {
    string theXML = Server.HtmlEncode(File.ReadAllText(Server.MapPath("~/XML/myxmlfile.xml")));
    lit1.Text = theXML;
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>Untitled Page</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <pre>
        <asp:Literal ID="lit1" runat="server" />
      </pre>
    </div>
  </form>
</body>
</html>

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

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