cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shai200 <shai...@gmail.com>
Subject Re: Character escaping problem with custom generator
Date Sun, 30 Mar 2008 17:32:57 GMT



> 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);
> }
> 
> 

Are you referring to org.apache.cocoon.core.xml.impl.JaxpSAXParser ?
I don't use a ServiceManager, but what if I instantiate the parser every
time? Will performance be low? And if I were to use the ServiceManager,
where would I store it? On the application level?

Also, should I still startDocument and endDocument like so? 

contentHandler.startDocument();
			contentHandler.startElement("", "content", "content", emptyAttr);
				parser.parse(is, contentHandler);
			contentHandler.endElement("","content","content");
			contentHandler.endDocument();

Or should I just ignore starting and ending the document, manually put the
<content> tag in my original xhtml String and jst parse the monster?


Joerg Heinicke wrote:
> 
> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Character-escaping-problem-with-custom-generator-tp16379318p16384597.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


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


Mime
View raw message