unescape() and escape styles question

R

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</b> Moby 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.
 
G

Gabriel Gilini

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top