I have string s and it looks:
<root><p>hello world</p> my name is!</root>
I have next code:
try
{
m_Content = XDocument.Load(new StringReader(s));
}
catch (XmlException ex)
{
ex.Data["myerror"] = s;
throw;
}
As you see, I want to load string with all elements like
and make it view. But I've got XmlException:
Reference to undeclared substitution to "nbsp"
Any ideas how to do it right?
ChrisShao offered a good idea: put my string in <![CDATA[
tag, but unfortunately it doesnt solve my problem. I have a big string with lots of tags and few big texts in which I can meet
elements. If use System.Web.HttpUtility.HtmlDecode
I lose all these elements and get " " fields.
Responding to your Added section. The blank ( " "
) fields you get is correct representation of
when it is rendered. Correct encoding of
for use in xml is  
[ Reference ].
If you really want to see
instead of " "
when the string loaded to XDocument
, try to encode ampersand char ( &
) with &
. Replace
with &nbsp;
[ Reference ].
使用System.Web.HttpUtility.HtmlDecode或System.Net.WebUtility.HtmlDecode
我认为您应该将字符串放入CDATA块中,如下所示:
<root><![CDATA[<p>hello world</p> my name is!]]></root>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.