473,471 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

unescape() and escape styles question

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
1 4171
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: TheKeith | last post by:
Hi, I'm just learning php now for the first time and I'm having a little trouble understanding something. In the following example: ...
1
by: koen colen | last post by:
Hello group, I hope you guys can help me out, I am modifying a piece of code from Joe Norman, I did found the code here: http://www.intranet2internet.com/public/default.asp?PAGE=sscript&ID=3 ...
2
by: Pavils Jurjans | last post by:
Hello, I am looking fow C# equivalent of JavaScripts escape() and unescape() functions. I need to use C# function at the server side and then be able to use the opposite at the client side. ...
2
by: Ravichandran Mahalingam | last post by:
Dear Readers, I am trying to construct an XML on the fly based on certain inputs. I have construct the whole request as string and then send it across. I need to have the following: <ARCXML...
10
by: Danny | last post by:
In the classic asp, I can use escape built-in function (server side function) like this: <script language=javascript> var myContent = unescape(<%=escape(strContent)%>) </script> How do I do...
1
by: Harry Keck | last post by:
Is there a set of methods in the .Net framework that do the same thing as the jscript functions escape and unescape? I get very close with HttpUtility.UrlEncodeUnicode, but it puts "+" for...
4
by: needin4mation | last post by:
Hi, string filename = "Directions2.xml"; XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath("Directions2.xml")); XmlElement root = doc.DocumentElement; XmlNode oldLoc; oldLoc =...
2
by: PJ6 | last post by:
I want to apply this style input { background-color: "#FFFFC0"; border-style: solid; border-width: 1px; } but only for input of type text. Do I have to use classes and tediously
4
by: Robert Mark Bram | last post by:
Hi All, I have an application that is writing Javascript with JSP server side code that uses escapeXML: var someVar = "<c:out escapeXml="true" value="You'll never escape!"/ How to I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.