Why is “ not showing up as a quote on my web page?

birdus picture birdus · Apr 10, 2013 · Viewed 8.9k times · Source

Other ASCII codes are doing the same thing.

Just to give you some background, these codes are part of the HTML that I'm reading from WordPress blog posts. I'm porting them over to BlogEngine.NET using a little C# WinForm app I wrote. Do I need to do some kind of conversion as I port them over to BlogEngine.NET (as XML files)?

It'd sure be nice if they just displayed properly without any intervention on my part.

Here's a code fragment from one of the WordPress source pages:

<link rel="alternate" type="application/rss+xml" title="INRIX® Traffic &raquo; Taking the &#8220;E&#8221; out of your &#8220;ETA&#8221; Comments Feed" href="http://www.inrixtraffic.com/blog/2012/taking-the-e-out-of-your-eta/feed/" />

Here's the corresponding chunk of XML that's in the XML file I output during the conversion:

<title>Taking the &amp;#8220;E&amp;#8221; out of your &amp;#8220;ETA&amp;#8221;</title>

UPDATE.

Tried this, but still no dice.

writer.WriteElementString("title", string.Format("<![CDATA[{0}]]>", post.Title));

...outputs this:

<title>&lt;![CDATA[Taking the &amp;#8220;E&amp;#8221; out of your &amp;#8220;ETA&amp;#8221;]]&gt;</title>

Answer

leemicw picture leemicw · Apr 11, 2013

Since the data you are getting from Wordpress is already encoded you can decode it to a regular string and then let the XMLWriter encode it properly for XML.

string input = "Taking the &#8220;E&#8221; out of your &#8220;ETA&#8221;";
string decoded = System.Net.WebUtility.HtmlDecode(input);
//decoded = Taking the "E" out of your "ETA"

This may not be very efficient, but since this sounds like a one time conversion I don' think it will be an issue.

A similar question was asked here: How can I decode HTML characters in C#?