Yes, it is a pain, isn't it? XML just doesn't care to know about or deal with whitespace, and that really is a pain when whitespace IS content!
To answer your question, it depends. If you just have a string (no XML markup in the database), then something like this is the easiest:
<xsp:logic>
String instring = <esql:get-string column="body"/>;
java.util.StringTokenizer st = new java.util.StringTokenizer(instring, "\n", true);
while (st.hasMoreTokens()) {
String token = st.nextToken();
if ("\n".equals(token)) {
<br/>
} else {
<xsp:expr>token</xsp:expr>
}
}
</xsp:logic>
If what is in your database contains XML markup, you'll need to do something more like this (mostly lifted from the ESQL logicsheet):
<xsp:logic>
String instring = <esql:get-string column="body"/>;
instring.replaceAll("\n", ">br/>");
org.apache.cocoon.components.parser.Parser newParser = null;
try {
newParser = (org.apache.cocoon.components.parser.Parser)
this.manager.lookup(org.apache.cocoon.components.parser.Parser.ROLE);
InputSource __is = new InputSource(new StringReader(rawXML));
XSPUtil.include(__is, this.contentHandler, newParser);
} catch (Exception e) {
getLogger().error("Could not include page", e);
} finally {
if (newParser != null) this.manager.release((Component) newParser);
}
</xsp:logic>
-Christopher
| Anders Forsgren <[EMAIL PROTECTED]>
11/04/2003 05:55 PM
|
To: [EMAIL PROTECTED] cc: Subject: Re: XSP/ESQL escaping |
Sigh :(
Feels like a lot of work to make a linebreak a <br/> tag...If I rephrase
the question: What would be the simplest way
of displaying the database strings with correct linebreaks in html
(except using <pre> in the xsl)?
thanks
Anders
