简体   繁体   English

使用 XML.InnerText 时保留 HTML 标记

[英]Retaining HTML Markup when using XML .InnerText

I have HTML markup being read from an XmlDocument using InnerText as below.我使用 InnerText 从 XmlDocument 读取 HTML 标记,如下所示。 However, once read into the string "content";但是,一旦读入字符串“content”;

string content = Convert.ToString(XmlDoc.DocumentElement.SelectSingleNode("/update/content").InnerText);

The HTML markup is lost. HTML 标记丢失。

How can I retain the HTML markup by the time the node content is in the string "content".当节点内容位于字符串“content”中时,如何保留 HTML 标记。

Solution is to use InnerXML as below, instead of InnerText.解决方案是如下所示使用 InnerXML,而不是 InnerText。

string content = Convert.ToString(XmlDoc.DocumentElement.SelectSingleNode("/update/content").InnerXml);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM