You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Martijn C. Vos" <m....@hippo.nl> on 2005/07/07 15:02:32 UTC

RE: XMLFileModule for a dynamic file.

I'm a bit late replying to this, but this sounds like something we do all the time
with almost all our projects, and we have a pretty simple solution for it which I
don't think I've seen here yet. (My apologies if someone else has already posted this.)

From: Alexander Berezhnoy [mailto:alexander.berezhnoy@splc.ru] wrote:

>  I want to extract data with XPath from an XML file whoes 
>  name depends on
>  request parameters.
>  The XMLFileModule is statically configured, so the file name 
>  is fixed.
>  
>  Please, is it possible without writing my own module?

Unlike its name suggests, the XMLFileModule doesn't have to read a real file. It
can also read the result of a pipeline. And that pipeline can still ask for the
request parameters.

Example:

In a pipeline in the sitemap:

<map:generate src="{file:/foo/bar}/file.xml"/>

Configuration of the input module:

<component-instance class="org.apache.cocoon.components.modules.input.XMLFileModule" name="file">
    <file src="cocoon://somepipeline.xml"/>
</component-instance>

Sitemap again:

<map:match pattern="somepipeline.xml">
  <map:generate src="data/{request-param:filename}.xml"/>
  <map:serialize/>
</map:match>

So this takes an XML file whose name depends on a request parameter, uses the XMLFileModule
to find a certain value from that file, and then uses the result as filename to get the file you really
want.

What we do is actually a bit more complicated than this, but this should work, as far as I know.


mcv.

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