this is because your string might be "something <b>bolded</d> and <i>italic</i>" which is not a valid xml because there is no single root element.This might help you and save some time writing code.
I had to get round the same problem the other day when i had to deal with strings of html from a database field coming into my jxtemplate. I found an old post of someone doing similar and modified their code to make it work for me, its all flow passed so quick to integrate.
I define a toSAX function before the call to sendPage and pass it in as bizdata like this
cocoon.sendPage("pipeline", {"buffer" : {"toSAX" : toSAX}});
Then in my template i do this sort of thing ${buffer.toSAX(htmlStr)} Which seems to work for me, i hope it helps you. Ideally this i suppose should be built as a tag or extension to jx:out within the jxtemplategenerator.
Heres the function:
function toSAX(str) { // i dont know why i need to wrap the string with something but it wouldnt work without it. var nStr = "<span>" + str + "</span>";
var is = new Packages.org.xml.sax.InputSource(new java.io.StringReader(nStr)); var parser = null; var buff = new Packages.org.apache.cocoon.xml.SaxBuffer(); try
{
parser = cocoon.getComponent(Packages.org.apache.excalibur.xml.sax.SAXParser.ROLE);
parser.parse(is, buff);
}
finally
{ if (parser != null)
cocoon.releaseComponent(parser); }
return buff;
}
some archive links: http://marc.theaimsgroup.com/?l=xml-cocoon-users&m=108222082629598&w=2
There is also a little bit better implementation (does not use SaxBuffer which lowers memory consumption) and allows for root element stripping:
http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=108680748429717&w=2
In this case you might also want to surround your string with some fake root element if you expect your data to be htmlish and not xml. The content might also not be a valid xml. you might then use JTidy or NekoHTML to clean it up first before parsing.
-- Leszek Gawron [EMAIL PROTECTED] Project Manager MobileBox sp. z o.o. +48 (61) 855 06 67 http://www.mobilebox.pl mobile: +48 (501) 720 812 fax: +48 (61) 853 29 65
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
