From alastair.rodgers at phocis.com Mon Dec 2 01:57:50 2002
From: alastair.rodgers at phocis.com (alastair.rodgers@phocis.com)
Date: Fri Aug 6 17:08:11 2004
Subject: [jdom-interest] "&" char in Javascript generated by JDOM
Message-ID: <651302258EF5D6119A7B00D0B74D694767A6@ph0103.phocis.com>
Hi Federico,
Can't you just use the old trick of embedding the JavaScript in an HTML
comment? Since HTML and XML comments are denoted by the same delimiters
(""), you can easily add the comment with JDOM.
So for example, you could have something along the lines of:
String js = "if (condition1 && condition2) alert(\"Conditions met!\");";
Element script = new Element("script");
script.addContent(new Comment(js));
This will result in the following HTML:
Since your JavaScript is in an XML comment, the '&' chars won't be escaped,
but HTML browsers will still interpret the JavaScript correctly.
Hope this helps.
Al.
> -----Original Message-----
> From: Federico [mailto:fmeschini@tin.it]
> Sent: 29 November 2002 17:06
> To: jdom-interest@jdom.org
> Subject: [jdom-interest] "&" char in Javascript generated by JDOM
>
>
> Hi all,
>
> I've written a java class for the automatic creation of a
> number of HTML files. I use the package JDOM for the creation
> of the HTML elements in the file. I have to insert a
> javascript function in the head
> section, so I
> creat a