cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Dumon <>
Subject Re: Injecting a String XML document into a pipeline
Date Sun, 05 Jun 2005 17:46:03 GMT
On Fri, 2005-06-03 at 16:46 -0500, Sebastien Arbogast wrote:
> Hi,
> I'm looking for a simple way to inject the string content of a
> flowscript variable into a pipeline for serialization and sending. Of
> course I could do a sendPage() but that would force me to :
> 1 - create a dummy JXTemplate to inject the value of my flow variable
> 2 - create an XSLT stylesheet to extract the content again.
> In other words, I'm in my flowscript function, I have a variable which
> contains exactly the XML document I want to send to the client. How
> can I do that ?

By using the module source. The module source is a source which finds
its input by using an input module. It can handle InputStreams, strings
or byte arrays.

Start the pipeline with a generator like this:

<map:generate src="module:flow-attr:myxml"/>

But since you have the XML already completely as you want to send it to
the client, you can directly use a reader which avoid the parsing and

<map:read src="module:flow-attr:myxml"/>

One possible issue might be encoding. If your XML string doens't contain
an encoding declaration, then an XML parser will treat it as UTF-8 so
the string should be converted to bytes using UTF-8. The module source
however uses whatever the platform default encoding is, so to avoid
problems it is better to convert to bytes already in your flowscript:

sendPage("...", {"myxml": myxmlvar.getBytes("UTF-8")});

(if your XML string does contain an encoding declaration, replace UTF-8
by whatever it specifies)

Bruno Dumon                   
Outerthought - Open Source, Java & XML Competence Support Center                

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message