Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 15416 invoked from network); 9 Jun 2004 05:31:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 9 Jun 2004 05:31:26 -0000 Received: (qmail 59310 invoked by uid 500); 9 Jun 2004 05:31:41 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 59269 invoked by uid 500); 9 Jun 2004 05:31:40 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: dev@cocoon.apache.org Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 59253 invoked by uid 99); 9 Jun 2004 05:31:40 -0000 Received: from [212.85.125.162] (HELO v07274.home.net.pl) (212.85.125.162) by apache.org (qpsmtpd/0.27.1) with SMTP; Tue, 08 Jun 2004 22:31:40 -0700 Received: from gprs1.idea.pl (HELO ?172.20.34.182?) (lgawron.mobilebox@home@194.9.223.27) by matrix15.home.net.pl with SMTP; 9 Jun 2004 05:30:57 -0000 Message-ID: <40C6A08A.3040207@mobilebox.pl> Date: Wed, 09 Jun 2004 07:30:50 +0200 From: Leszek Gawron User-Agent: Mozilla Thunderbird 0.6 (Windows/20040502) X-Accept-Language: en-us, en MIME-Version: 1.0 To: dev@cocoon.apache.org Subject: Re: REQ: An "escapeXml" attribute in JXT macro/script output References: <20040608230938.4692.qmail@web52610.mail.yahoo.com> In-Reply-To: <20040608230938.4692.qmail@web52610.mail.yahoo.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Terry Brick wrote: > Hello, > This request is carried over from the users list regarding introducing XML from a > variable/component into the JXT output stream. > For example, let's say I have Java bean with a String property that holds XML text. If, in my > template, I do something like... > ${MyBean.XML} > ... Then all of the XML characters are escaped. > For example, > > ..becomes.. > <para> > > I would think that for most Cocoon users, this is undesirable behavior most of the time. > The current workaround is to have the bean property return a DOM Document instead of a String. > However, in many cases, other than to accomodate this workaround, I have no other need to create a > DOM document within my Java component.... so it seems like there could be some unecessary overhead > associated with doing that. I guess that depends on how Cocoon handles the doc... maybe it's a > wash. > Anyway, an escapeXml="true/false" attribute on the JX output tags (similar to JSTL) would > certainly be handy IMO. > > Thanks! Solution: >> function stringToSAX( str, consumer, ignoreRootElement ) { >> var is = new Packages.org.xml.sax.InputSource( new java.io.StringReader( str ) ); >> var ignore = ( ignoreRootElement == "true" ); >> var parser = null; >> var includeConsumer = new org.apache.cocoon.xml.IncludeXMLConsumer( consumer, consumer ); >> includeConsumer.setIgnoreRootElement( true ); >> try { >> parser = cocoon.getComponent( Packages.org.apache.excalibur.xml.sax.SAXParser.ROLE ); >> parser.parse( is, includeConsumer ); >> } finally { >> if ( parser != null ) cocoon.releaseComponent( parser ); >> } >> } put it into session by cocoon.session.setAttribute( "saxer", stringToSAX ); implement a jx:macro: >> >> >> >> >> > use it like this: and you're done. LG