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: Adam Constabaris <adamc AT unc.edu>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] javascript
  • Date: Fri, 06 May 2005 09:33:36 -0400

John Cowan wrote:
Luca Passani scripsit:


How do I force XOM to diplay '<' and not &lt; ?


You don't want it to. Remember that XOM is generating XML, not HTML, and
in XML, a < character may appear only at the beginning of a tag. If
XOM were to do what you want it to, the output would not be well-formed
(which is another way of saying it is not XML at all).

If you want to write HTML output, you can use the hacked version of
XMLWriter packaged with TagSoup.


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

--
Adam Constabaris
Applications Analyst
ITS Knowledge Management
UNC-CH




Archive powered by MHonArc 2.6.24.

Top of Page