cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven Dolg <>
Subject Re: Cocoon3 newbie help
Date Wed, 05 Oct 2011 07:44:15 GMT
Am 05.10.2011 00:08, schrieb Marzia Forli:
> I am a xml processing newbie, who have to read-transform-write some pretty big xml files,
and in my journey to the jaxp land I stumbled upon this wonderful library... Here I ask for
some kind advice regarding the my problem. For my case let's imagine that we have a pretty
big pom.xml and I would have to do the following:
> 1) if under the tag 'repositories/repository/name' in the body is present string 'snapshots'
then rewrite the 'url' element stripping out the tags and make it uppercase...
> 2) given the dependencies/dependency/groupId element if there is one dependency with
groupId = 'org.apache.cocoon.sax' then i have to get and rewrite all dependencies elements
> to make it simple if I found a desired element then I have to operate on containing element
rewriting it... Transformations I have to do a without the xslt.
> Maybe what I am asking seems trivial or plain stupid but I am not an expert just learning...
Is this library right for this task and if yes what would be the right approach to handle
this. Many many thanks

Cocoon 3 is certainly the right tool for that task.
Both SAX and StAX components will work fine and cause you no trouble 
with file size, since they stream the file instead of loading it all 

You actually have a couple of options to achieve what you have mentioned:
1) You could implement the modifications using XSLT and use an existing 
XSLT-Transformer (I saw your "without the XSLT", just added for 

2) You could implement your own transformer and express the 
transformations in pure Java.
      Both SAX and StAX can do this. I'd choose StAX for that (the 
Navigators are quite handy!), but it's really what you prefer / know better.
      You can take a look at

as example for a StAXTransformer using Navigators.

3) You could always go with more advanced options like controllers, but 
IMO that's really overkill for this.

Depending on how you want to execute this (embedded into another 
application / stand-alone application / web-service) you will want to 
use different Cocoon modules.
The easiest way for experimenting is using the Pipeline API directly.

This could look something like this:

Pipeline<SAXPipelineComponent>  pipeline=  new  NonCachingPipeline<SAXPipelineComponent>();
pipeline.addComponent(new  XMLGenerator(new  URL("file://path/to/pom.xml")));
pipeline.addComponent(new  MyPomTransformer());
pipeline.addComponent(new  XMLSerializer());

pipeline.setup(new FileOutputStream("/path/to/modified-pom.xml");

Hope that helps a litte.
I'm sure you'll have further questions, tho... ;)


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

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

View raw message