473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unescape escapeXML text

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!");

Do I have to use regex to replace or is there some other way?

Thanks for any assistance!

Rob
:)
Oct 14 '08 #1
4 11372
Robert Mark Bram wrote:
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!");

Do I have to use regex to replace or is there some other way?
var txt = 'apostrophe ' / double quote: " / '
+ ' s: s / č: è / Chinese sign: 新';

txt = txt.replace(/(&#)([0-9]{1,5})(;)/g,
function (a1, a2, a3, a4) {
return String.fromCharCode(a3);
}
);
alert(txt);

Hope this helps,

--
Bart
Oct 14 '08 #2
Robert Mark Bram wrote:
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!");
Or could escape it differently.

If you are using struts you can use StringEscapeUtils.escapeJavaScript.

Would be really nice to have c:out handle that.

Fictitious example:
<c:out escapeJavaScript="true" value="You'll never escape!"/>

Garrett
>
Rob
:)

--
comp.lang.javascript FAQ <URL: http://jibbering.com/faq/ >
Oct 14 '08 #3
Robert Mark Bram wrote:
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!"/>";
*g*
How to I unescape this?
Maybe

someVar = someVar.replace(/&lt;/g, "<").replace(/&gt;/g, ">"
.replace(/&amp;/g, "&");
Using the unescape() function doesn't cut it..
unescape("You'll never escape!");
It is not supposed to. unescape() decodes (ASCII) percent-encoded strings.
It was primarily used to decode URI components, and is now deprecated in
favor of decodeURI() and decodeURIComponent(), which in addition can decode
UTF-8 percent encoding.
Do I have to use regex to replace or is there some other way?
A regular expression like above would not help in your case because the
escaping of `"' needs to take place *before* you insert the value with JSP,
i.e. "on the server".

You do not need `escapeXml="true"' if you declare the content of the XHTML
`script' element CDATA, provided the string never contains `"', like
in your example:

<script type="text/javascript">
// <![CDATA[
...
]]>
</script>

But if the `<' and `>' are your only problems, you could as well move the
code to an external script file or simply use HTML instead.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Oct 15 '08 #4
Thanks to all for the input!
Oct 16 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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: karteikarte | last post by:
hey, i just found this riddle somewhere in the net: <meta http-equiv="Pragma" content="no-cache"> <script language="JavaScript"> <!-- function nstie(){return false}function...
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...
30
by: mistral | last post by:
Neeed good javascript unescape encoder, to protect javascript code. Some advices? Online tool, or ready javascript only. Any opinions about the Javascript Obfuscator:...
2
by: Richard Lewis Haggard | last post by:
Is it possible to use features from XmlDocument to unescape text back to its original raw text format after it has been escaped to handle non-HTML compliant character strings? I have code that...
2
by: Richard Lewis Haggard | last post by:
Is it possible to use features from XmlDocument to unescape text back to its original raw text format after it has been escaped to handle non-HTML compliant character strings? I have code that...
3
by: mistral | last post by:
How to decrypt this text, what algorithm used to encode text, how to recreate algorithm? %c3%99%c3%a3%c3%af%c3%b3%c3%94%c3%92%c3%89%c3%81%c3%8c%c3%ae%c3%ba...
1
by: RK | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.