Page: http://wiki.cocoondev.org/Wiki.jsp?page=Scherler , version: 29 on Sat Apr
5 11:04:13 2003 by Scherler
+ \\
+ ''convert string to xml''
+ {{{Aparently your <xsp:expr>result</xsp:expr> returns a string and not and
XML stream.
+ You can use JTidy to convert your String to an XML stream. It's classes are
available in Cocoon!
+ Here's a code snip out of an XSP page that converts a POST from a brower
based html editor to an XML stream.
+ <xsp:structure>
+ <xsp:include>org.w3c.tidy.Tidy</xsp:include>
+ <xsp:include>java.io.ByteArrayInputStream</xsp:include>
+ </xsp:structure>
+ <page>
+ <xsp:logic>
+ String strContent = request.getParameter("content");
+ ByteArrayInputStream in = new ByteArrayInputStream(
strContent.getBytes() );
+ org.w3c.dom.Document doc = null;
+ org.w3c.tidy.Configuration conf = new org.w3c.tidy.Configuration();
+
+ try {
+ Tidy tidy = new Tidy();
+ //Do not show "parsing" messages
+ tidy.setQuiet(true);
+ //Do not show warnings in the Servlet Engine console
+ tidy.setShowWarnings(false);
+ //set the output type
+ tidy.setXmlOut(true);
+ //Set the encoding
+ tidy.setCharEncoding( conf.LATIN1 );
+ //Set output options
+ tidy.setBreakBeforeBR(false);
+ tidy.setQuoteNbsp(true);
+ tidy.setQuoteAmpersand(true);
+ tidy.setLiteralAttribs(true);
+ //Omit the document type in the tidy output
+ tidy.setXmlPi(false);
+ //parse the document tot a DOM tree
+ doc = tidy.parseDOM(in, null);
+ } catch (Exception e) {
+ //Do some error handling here
+ }
+ </xsp:logic>
+ <content>
+ <xsp:expr>doc.getDocumentElement()</xsp:expr>
+ </content>
+
+
+ You will need to tweak the Tidy parameters, but you get the idea, I guess.
+ The DOM stream from JTidy is automatically converted to SAX by Cocoon
(correct me if I'm wrong) so you can do regular transformations in the pipeline
afterwards.
+
+ HTH,
+ Bert }}}
+