Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] javascript

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Luca Passani <passani AT eunet.no>
  • To: Adam Constabaris <adamc AT unc.edu>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] javascript
  • Date: Fri, 06 May 2005 15:55:12 +0200

This one did the trick. Thanks a lot.

Luca

Adam Constabaris wrote:


An alternate, which requires careful work, is to wrap the contents of your script in a Comment element. This will 'preserve' the < in the body of the comment; since, however, JavaScript parsers don't recognize the end part of the XML comment ("-->"), so if you don't want the inserted script to cause JavaScript errors, you need to make sure the final bit of text in the comment is "// ", e.g.

Element root = new Element("script");
StringBuilder b = new StringBuilder();
b.append("function foo() {\n")
.append("\tif ( 7 < 9 ) {\n")
.append("\t\tdocument.writeln('yep');\n")
.append("\t}\n}\n // ");
Comment comment = new Comment(b.toString());
root.appendChild(comment);
System.out.println(root.toXML());

(if you're on a pre-1.5 JDK, change that StringBuilder to a StringBuffer)

cheers






Archive powered by MHonArc 2.6.24.

Top of Page