Unescape strings in Javascript
<p>I need to unescape strings in Javascript, but my string sometimes is already unescaped, and other times it is not:</p>

<pre><code>// String 1
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; ?&amp;gt;

// String 2
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
</code></pre>

<p>I use the following method:</p>

<pre><code>function htmlDecode(input)
{
  var doc = new DOMParser().parseFromString(input, "text/html");
  return doc.documentElement.textContent;
}
</code></pre>

<p>But the problem is that when I "decode" string 2, the answer comes out as <code>?xml version="1.0" encoding="UTF-8"?</code> </p>

<p>Help is appreciated.</p>