We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Displaying "&" instead of &amp
Page Index Toggle Pages: 1
Displaying "&" instead of &amp (Read 3847 times)
Displaying "&" instead of &amp
Nov 15th, 2007, 7:23pm
 
Hi,

I'm using the proXML library to load some XML strings from a server.

My problem is when the string contains an "&" (which is the HTML code for "&") Processing displays "&" which is totally logic since it's what Processing receives. My problem is, I want to display "&" and not "&".

I've tried changing manually the XML file with "&" already inside them but I get the following error.

java.lang.RuntimeException: Illegal use of &. Use & entity instead. Line:138
at proxml.XMLInOut$Loader.handleEntity(XMLInOut.java:398)

I also tried to change the XML to the processing escape character but what got displayed was the "\u00..."

My next solution would be, in Processing, search the string for & and then replace it with "\u00..." but before I do that I was wondering if there is an easier way of converting these HTML characters to show them properly.

Thanks.

PS: I couldn't actually find the Processing escape characters for "&" in Fry/Reas's book. Anyone knows it? In my example I used another character to test my possible solutions.
Re: Displaying "&" instead of &a
Reply #1 - Nov 15th, 2007, 8:06pm
 
Your code has to interpret & style entities itself. & is a special character in XML, so you can't just put a plain & in a file no matter how you try to treat it.

However, there is an easy way to change & into &

Code:
myString.replaceAll("&","&");
Re: Displaying "&" instead of &a
Reply #2 - Nov 15th, 2007, 8:16pm
 
steven wrote on Nov 15th, 2007, 7:23pm:
PS: I couldn't actually find the Processing escape characters for "&" in Fry/Reas's book. Anyone knows it In my example I used another character to test my possible solutions.

that's because it's ascii, and doesn't need an escape sequence.
Re: Displaying "&" instead of &a
Reply #3 - Nov 15th, 2007, 9:49pm
 
Thanks!
Re: Displaying "&" instead of &a
Reply #4 - Nov 16th, 2007, 8:09am
 
More generally, what you want to do is unescape the entire sequence -- sometimes you'll run into other characters that get escapes in URL encoding, too.

I use the string escape utils from Apache Commons --

http://commons.apache.org/lang/api/org/apache/commons/lang/StringEscapeUtils.html

-- which works great.
Re: Displaying "&" instead of
Reply #5 - Oct 13th, 2009, 4:02am
 
Hello,

I am trying to use the string escape from Apache Commons as sugested in former post, but I have some trouble getting it to work.

I downloaded the .jar (commons-lang-2.4.jar) and add it to my sketch but i gives an error when i try to run the sketch "Syntax error on token "enum", identifier expected"

I have the feeling I am forgetting something or not doing it right.

Any help or assistance would be greatly appreciated...

Thanks in Advance

Machiel
Re: Displaying "&" instead of
Reply #6 - Jun 15th, 2010, 9:07am
 
I am trying to do the exact same thing, and I am getting the same error.
Machiel, did you manage to solve the problem?

Can anyone guide me as to what I would have to do here?

Thanks,
Akshay
Page Index Toggle Pages: 1