cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Krulewitz <sh...@mm.st>
Subject Serving XHTML with Cocoon (was: Empty elements and the XML Serializer)
Date Tue, 23 Mar 2004 04:48:09 GMT
Thanks to everyone who responded to the "Empty elements and the XML 
Serializer" thread.  Rather than change the way documents are 
serialized, the proper solution is to deliver the content to the browser 
in such a way that the browser knows it is getting XHTML.

First of all, you need to  specify an XHTML doctype and use the XHTML 
namespace for the xhtml elements in your document.  You also need to 
send the "application/xhtml+xml" content type with your response.  But 
here is the problem -- Internet Explorer does not like this, and will 
attempt to download the page if it receives this content type.  It seems 
to work for most other browsers, but for Internet Explorer you still 
need to send the content as "text/html".

To handle this in Cocoon, I've declared two separate serializers:

<map:serializer
   name="xhtml"
   mime-type="application/xhtml+xml; charset=utf-8"
   src="org.apache.cocoon.serialization.XMLSerializer"
 >
   <doctype-public>-//W3C//DTD XHTML 1.0 Strict//EN</doctype-public>
 
<doctype-system>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</doctype-system>
   <encoding>UTF-8</encoding>
   <indent>yes</indent>
</map:serializer>

<map:serializer
   name="xhtml-ie"
   mime-type="text/html; charset=utf-8"
   src="org.apache.cocoon.serialization.XMLSerializer"
 >
   <doctype-public>-//W3C//DTD XHTML 1.0 Strict//EN</doctype-public>
 
<doctype-system>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</doctype-system>
   <encoding>UTF-8</encoding>
   <indent>yes</indent>
</map:serializer>

And also a resource that is used in place of <map:serialize/>:

<map:resources>
   <map:resource name="serialize">
     <map:select type="browser">
       <map:when test="explorer">
         <map:serialize type="xhtml-ie"/>
       </map:when>
       <map:otherwise>
         <map:serialize type="xhtml"/>
       </map:otherwise>
     </map:select>
   </map:resource>
</map:resources>

So instead of calling <map:serialize/>, i call <map:call 
resource="serialize"/>.

The bad part about using a resource is that, as far as I know, a 
resource declared in the root sitemap can not be called by subsitemaps.

Is this on par with other people's experience dealing with this problem?

cheers,
-steve

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


Mime
View raw message