我有一个html编码字符串,我想从xml文档中提取并以文字显示。我的代码如下所示:
XML
<test>&lt;p&gt;Here is a &lt;em&gt;test&lt;/em&gt; to &lt;strong&gt;consider&lt;/strong&gt;&lt;/p&gt;
</test>代码背后
ccXML.Load(Server.MapPath("~/customContent.xml"));
var welcomeMessage = ccXML.SelectSingleNode("/test");
string message = welcomeMessage.InnerXml;
storyBox.Text = Server.HtmlDecode(message);HTML
<asp:Literal ID="storyBox" Mode="PassThrough" runat="server"></asp:Literal>当前,文字正在向用户显示html标记,如下所示
"<p>Here is a <em>test</em> to <strong>consider</strong></p>." 相反,我想要的是执行标记(即格式化文本)。有人看到我哪里出问题了吗?提前感谢您的帮助。
编辑:有人引导我到另一个线程(C# ASP.net render HTML String )上的这个先前的答案,但是解决方案(将我的字符串转换为字符串)没有解决这个问题。
发布于 2015-06-30 16:22:33
当我编码目标HTML时,我得到以下内容:
<p>Here is a <em>test</em> to <strong>consider</strong></p>当我在<test>元素中使用它时,它对我很好。
https://stackoverflow.com/questions/31143183
复制相似问题