cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joerg Heinicke <joerg.heini...@gmx.de>
Subject Re: Character escaping problem with custom generator
Date Sun, 30 Mar 2008 08:01:57 GMT
On 30.03.2008 03:39, shai200 wrote:
> I have a custom generator with a generate() method that looks like this:
> public void generate() throws IOException, SAXException, ProcessingException
> {
> 		
> 		contentHandler.startDocument();
> 			contentHandler.startElement("", "content", "content", emptyAttr);
> 				contentHandler.characters(xhtml_output.toCharArray(), 0,
> xhtml_output.length());
> 			contentHandler.endElement("","content","content");
> 		contentHandler.endDocument();
> 	}
> 
> where xhtml_output is some html code. 
> 
> My sitemap entry looks like this:
> 
> <map:match pattern="xmlaction">
> 	 <map:generate type="skunk" />
> 	<map:serialize type="xml"/>
> </map:match>
> 
> The problem is that this returns HTML code with escaped characters ( i.e. &
> lt;  and & gt; instead of < and >, etc.)

You have to actually parse the XHTML, not pass its content as 
characters. I came across a class today, StringXMLizable, that can help 
you if you don't want to do the parsing yourself:

new StringXMLizable(xhtml_output).toSAX(contentHandler);

If you have a ServiceManager available (Serviceable) you can also do the 
parsing yourself:

SAXParser parser = null;
try {
     parser = (SAXParser) manager.lookup(SAXParser.ROLE);
     InputSource is = new InputSource(new StringReader(xhtml_output));
     parser.parse(is, contentHandler);
} finally {
     manager.release(parser);
}

The second approach is definitely preferable, especially since 
StringXMLizable has a questionable implementation [1] not using Cocoon's 
infrastructure.

Joerg

[1] http://marc.info/?l=xml-cocoon-dev&m=120685987703854&w=4

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message