By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,625 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,625 IT Pros & Developers. It's quick & easy.

unescape() and escape styles question

P: n/a
RK
Perhaps I'm confused somwhere in my understanding, but I'm trying to
deal with some escaped text from an XML file which includes html markup
and it appears there are a couple of techniques for escape codes.

(I hope I can describe my issue here without having to worry about how
to escape it for display on this group!)

On the server-side I extract some text from an XML file, which includes
some style and content. The XML is simply:

<text&lt; b &gt;Title&lt; /b &gt; Moby Dick </text>

This is ampersand escaped bold tags within the xml file. An XML parser
on server side reads it nicely and sends it to my javascript on the
client side.

The javascript uses the XML content from an XmlHttpRequest and needs to
stick it into a webpage with

txtmsg = mystuff.getElementsByTagName("text")[0].firstChild.nodeValue;
document.getElementById(thisline).innerHTML=txtmsg ;

and of course it shows up in my browser as

<b>Title</bMoby Dick

....instead of with the word 'title' in bold.

I discovered a Javascript unescape() function, but it doesn't seem to
work for me. It appears the companion function "escape()" in javascript
uses percentage-signs to do the escaping.

Is there some means to unescape the ampersand-based escapes in
javascript, so that I can insert HTML that will get interpreted by the
browser?
Thanks in advance for any suggestions,

Ross.
Nov 12 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Nov 12, 5:23*pm, RK <ross@rosswrote:
[snip]
Is there some means to unescape the ampersand-based escapes in
javascript, so that I can insert HTML that will get interpreted by the
browser?
Hi Ross,
a little googling around made me find[1] this trick:

function unescapeHTML(html) {
var htmlNode = document.createElement("DIV");
htmlNode.innerHTML = html;
if(htmlNode.innerText)
return htmlNode.innerText; // IE
return htmlNode.textContent; // FF
}

[1] http://www.jibbering.com/faq/index.html

Cheers

Gabriel Gilini
Nov 12 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.