473,761 Members | 9,864 Online
Bytes | Software Development & Data Engineering Community
+ 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.getElem entsByTagName(" text")[0].firstChild.nod eValue;
document.getEle mentById(thisli ne).innerHTML=t xtmsg;

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 4188
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(ht ml) {
var htmlNode = document.create Element("DIV");
htmlNode.innerH TML = html;
if(htmlNode.inn erText)
return htmlNode.innerT ext; // IE
return htmlNode.textCo ntent; // 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
2592
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: ------------------------------------------------------------------------ <?php function test ($thenum) {
1
5537
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 My question: How can I save the value's of a form to a cookie, but in the textarea's of that form the "hard returns" must be saved with it?
2
14479
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. JavaScripts escape() function converts all non-alphanumerical chars to %xx, and all unicode chars to %uxxxx (where xxxx is unicode charcode). I'd like to have C# function that get this escaped string back to normal at the server side. Perhaps there...
2
2520
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 version="1.1"> <REQUEST> ..
10
8357
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 that in asp.net? Seems like escape server side function is no longer provided in asp.net, or am I missing something here?
1
3195
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 spaces instead of "%20". Uri.EscapeString seems to create the correct escape string, but there is no unescape. The function is not public anyway, so I probably shouldn't use it. I need a way to escape text on the client, and then unescape it on the...
4
2580
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 = root.SelectSingleNode("/NewDataSet/Locations"); XmlElement newLoc = doc.CreateElement("Locations");
2
929
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
11389
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 unescape this? Using the unescape() function doesn't cut it.. unescape("You'll never escape!");
0
9531
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10115
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9775
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
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 we have to send another system

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.