Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I escape a literal unicode expression?  RSS feed

 
Robyn Sambo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a jsp scriptlet that outputs an xml file. The xml file contains blocks of text with html tags. In order for the xml structure to retain it's integrity, the html tags need to be written as unicode or html entities ie: > or 003E.
here is a piece of my scriptlet.
String cleanContent1= copy.replace('>', '\u003E');
the problem is that java compiles the unicode expression and outputs a >. So it's replacing > with > when I really want it to output the literal text "\u003E".
Any ideas?
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"\u003E" --> "&"
"\\u003E" --> "u003E"
"\\" --> "\"
"\\" + "\\u003E" --> "\u003E"

Using entities is easier.

You are better off using a class like this. You can probably use a tag for that, and this has probably been done a few times.
You'd end up with something like:

It's a better approach.
[ August 23, 2003: Message edited by: Garrett Smith ]
 
Robyn Sambo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info.
When I try the double backslash
String cleanContent1= copy.replace('>', '\\u003E');
I get the error:
/opt/jakarta-tomcat-4.1.12/work/Standalone/monopole.us/_/jsp/viewContentDetail_jsp.java:101: unclosed character literal
String cleanContent1= copy.replace('>', '\\u003E');

-----
Not sure why...any ideas.
I will try looking for a tag that will handle this character replacing.
Any ideas on where I can find something like this?
thanks
Robyn Sambo
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!