You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Derek Hohls <DH...@csir.co.za> on 2004/07/08 09:41:04 UTC

Reading XML data from flowscript

Is there is a simple function in flow script that 
will allow me to:
- access a specified XML file (say, passed as a 
request/sitemap parameter)
- read in one or nodes from the file and store
these as flowscript variables.

Thanks
Derek

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.


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


Re: Reading XML data from flowscript

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Peter Velychko wrote:

> Hello Peter,
> 
> Some corrections. I looked at mail of Leszek Gawron and uderstand that
> I forgotten to release components used.
> Taking into account the message of Leszek it sould be:
> 
> var uri = cocoon.parameters.myUri;
> try {
>         var resolver = cocoon.getComponent(Packages.org.apache.excalibur.source.SourceResolver.ROLE);
>         var parser = cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
>         var xpathProcessor = cocoon.getComponent(Packages.org.apache.excalibur.xml.xpath.XPathProcessor.ROLE);
>         
>         var source = resolver.resolveURI(uri);
>         var document = Packages.org.apache.cocoon.components.source.SourceUtil.toDOM(source);
>         
>         var result = xpathProcessor.evaluateAsString(document,'/config/lang');
>         
> } finally {     
>         resolver.release(source);
>         cocoon.releaseComponent(resolver);
>         cocoon.releaseComponent(parser);
>         cocoon.releaseComponent(xpathProcessor);
> }
I think you should check for nulls also (I do not know if 
cocoon.releaseComponent accepts null)

-- 
Leszek Gawron                                      lgawron@mobilebox.pl
Project Manager                                    MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

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


Re: Reading XML data from flowscript

Posted by Peter Velychko <ve...@mail.ru>.
Hello Peter,

Some corrections. I looked at mail of Leszek Gawron and uderstand that
I forgotten to release components used.
Taking into account the message of Leszek it sould be:

var uri = cocoon.parameters.myUri;
try {
        var resolver = cocoon.getComponent(Packages.org.apache.excalibur.source.SourceResolver.ROLE);
        var parser = cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
        var xpathProcessor = cocoon.getComponent(Packages.org.apache.excalibur.xml.xpath.XPathProcessor.ROLE);
        
        var source = resolver.resolveURI(uri);
        var document = Packages.org.apache.cocoon.components.source.SourceUtil.toDOM(source);
        
        var result = xpathProcessor.evaluateAsString(document,'/config/lang');
        
} finally {     
        resolver.release(source);
        cocoon.releaseComponent(resolver);
        cocoon.releaseComponent(parser);
        cocoon.releaseComponent(xpathProcessor);
}

Thursday, July 8, 2004, 12:01:14 PM, you wrote:

PV> Hello Derek,

PV> Try to use the following

PV> function testPage() {
PV>         var uri = cocoon.parameters.myUri;
        
PV>         var resolver = cocoon.getComponent(Packages.org.apache.excalibur.source.SourceResolver.ROLE);
PV>         var parser = cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
PV>         var xpathProcessor = cocoon.getComponent(Packages.org.apache.excalibur.xml.xpath.XPathProcessor.ROLE);
        
PV>         var source = resolver.resolveURI(uri);
PV>         var is = Packages.org.apache.cocoon.components.source.SourceUtil.getInputSource(source);
PV>         var document = parser.parseDocument(is);
PV>         print("res="+xpathProcessor.evaluateAsString(document,'/config/lang'))
PV> }

PV> Thursday, July 8, 2004, 10:41:04 AM, you wrote:

DH>> Is there is a simple function in flow script that 
DH>> will allow me to:
DH>> - access a specified XML file (say, passed as a 
DH>> request/sitemap parameter)
DH>> - read in one or nodes from the file and store
DH>> these as flowscript variables.

DH>> Thanks
DH>> Derek

-- 
Best regards,
Peter
velychko_peter@mail.ru


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


Re: Reading XML data from flowscript

Posted by Peter Velychko <ve...@mail.ru>.
Hello Derek,

Try to use the following

function testPage() {
        var uri = cocoon.parameters.myUri;
        
        var resolver = cocoon.getComponent(Packages.org.apache.excalibur.source.SourceResolver.ROLE);
        var parser = cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
        var xpathProcessor = cocoon.getComponent(Packages.org.apache.excalibur.xml.xpath.XPathProcessor.ROLE);
        
        var source = resolver.resolveURI(uri);
        var is = Packages.org.apache.cocoon.components.source.SourceUtil.getInputSource(source);
        var document = parser.parseDocument(is);
        print("res="+xpathProcessor.evaluateAsString(document,'/config/lang'))
}

Thursday, July 8, 2004, 10:41:04 AM, you wrote:

DH> Is there is a simple function in flow script that 
DH> will allow me to:
DH> - access a specified XML file (say, passed as a 
DH> request/sitemap parameter)
DH> - read in one or nodes from the file and store
DH> these as flowscript variables.

DH> Thanks
DH> Derek

-- 
Best regards,
Peter
velychko_peter@mail.ru


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


Re: Reading XML data from flowscript

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Derek Hohls wrote:

> Is there is a simple function in flow script that 
> will allow me to:
> - access a specified XML file (say, passed as a 
> request/sitemap parameter)
you can get DOM from supplied uri via this code:

> 	var resolver = null;
> 	var source = null;
> 	try {
> 		resolver = cocoon.getComponent( SourceResolver.ROLE );
> 		source = resolver.resolveURI( yourURI ); 
> 		var document = SourceUtil.toDOM( source );
> 		
 >		// process your document here
> 	} finally { 
> 		if ( resolver != null ) { 
> 			if ( source != null )  
> 				resolver.release( source );
> 			cocoon.releaseComponent( resolver );
> 		}
> 	}

> - read in one or nodes from the file and store
> these as flowscript variables.
use XPathApi
http://xml.apache.org/xalan-j/apidocs/org/apache/xpath/XPathAPI.html

> 
> Thanks
> Derek
> 


-- 
Leszek Gawron                                      lgawron@mobilebox.pl
Project Manager                                    MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65


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