You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jeff Jones <JA...@weather.com> on 2004/07/28 23:45:59 UTC

How can I extract values from XML within an Action?

I'm getting lost in Cocoon docs and could use a pointer or two. Could anyone
help me out?

I'm writing an Action to perform the following steps:

   Pull a couple query parameter values from the request URI
   Perform some simple Java manipulation on them
   Use the manipulated values to request an XML document, either externally
(http://) or internally (cocoon://)
   Extract several values from the resulting XML document and insert them into
the action result map
   Return the map to the pipeline

The only thing I don't see how to do is extract data from the XML document; or,
to put it another way, I don't see how to use an XML document as the source of
data for an Action. I realize I'm probably missing something simple, but I'm
kind of stuck on this point... or maybe I should be using something other than
an Action to begin with. Can anyone give me a push in the right direction?

Many thanks,

Jeff Jones
The Weather Channel Interactive



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


Re: How can I extract values from XML within an Action?

Posted by Olivier Billard <ob...@jouve.fr>.
Hi Jeff,

The source resolving mechanism is for you :).

SourceResolver resolver = null;
Source source = null;

try {
	resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
	processor =
		(XPathProcessor) manager.lookup(XPathProcessor.ROLE);

	source = resolver.resolveURI("cocoon://blah");
	// or source = resolver.resolveURI("http://blah");
	
	// then do what you want from your source : get the file, the	
	//input stream, and so on...
} catch (ComponentException e) {
	getLogger().error("Could not lookup for component : ", e);
	throw new CascadingRuntimeException(e.getMessage(), e);
} finally {
	if (resolver != null) {
		if (source != null)
			resolver.release(source);
		manager.release(resolver);
	}
}

Your Action must be Serviceable (ie must extend ServiceableAction) to 
get access to the cocoon component manager.

--
Olivier Billard

Jeff Jones wrote:
> I'm getting lost in Cocoon docs and could use a pointer or two. Could anyone
> help me out?
> 
> I'm writing an Action to perform the following steps:
> 
>    Pull a couple query parameter values from the request URI
>    Perform some simple Java manipulation on them
>    Use the manipulated values to request an XML document, either externally
> (http://) or internally (cocoon://)
>    Extract several values from the resulting XML document and insert them into
> the action result map
>    Return the map to the pipeline
> 
> The only thing I don't see how to do is extract data from the XML document; or,
> to put it another way, I don't see how to use an XML document as the source of
> data for an Action. I realize I'm probably missing something simple, but I'm
> kind of stuck on this point... or maybe I should be using something other than
> an Action to begin with. Can anyone give me a push in the right direction?
> 
> Many thanks,
> 
> Jeff Jones
> The Weather Channel Interactive


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