You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by ho...@armacell.com on 2006/02/06 09:19:07 UTC
Getting XML data into Flowscript
Hi,
I am trying to extract data from a XML source (XML file or Cocoon
pipeline) for use in a flowscript (actually it's an XML file containing
quiz questions and the correct answers. I need to extract the answers to
test if the user selected the correct choice).
Any ideas?
Regards
Holger
Antwort: Re: Getting XML data into Flowscript
Posted by ho...@armacell.com.
Thank you very much! This saved me many hours of research!
Regards
Holger
news <ne...@sea.gmane.org> schrieb am 06.02.2006 22:16:09:
> holger.willenborg@armacell.com wrote:
> >
> > Is loadDocument(String) a function that you implemented? I only got an
> > error message.
>
> Gee... I forgot to add this:
>
> /*
> Loads the contents of an XML document given as an URI and returns it
as
> a DOM object.
> */
> function loadDocument(uri) {
> var parser = null;
> var source = null;
> var resolver = null;
> try {
> parser =
>
cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
> resolver =
> cocoon.getComponent(Packages.org.apache.cocoon.environment.
> SourceResolver.ROLE);
> source = resolver.resolveURI(uri);
> var is = new
> Packages.org.xml.sax.InputSource(source.getInputStream());
> is.setSystemId(source.getURI());
> return parser.parseDocument(is);
> } finally {
> if (source != null)
> resolver.release(source);
> cocoon.releaseComponent(parser);
> cocoon.releaseComponent(resolver);
> }
> }
>
> Regards,
>
> --------------------
> Luca Morandini
> www.lucamorandini.it
> --------------------
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
Re: Getting XML data into Flowscript
Posted by Luca Morandini <lm...@ieee.org>.
holger.willenborg@armacell.com wrote:
>
> Is loadDocument(String) a function that you implemented? I only got an
> error message.
Gee... I forgot to add this:
/*
Loads the contents of an XML document given as an URI and returns it as
a DOM object.
*/
function loadDocument(uri) {
var parser = null;
var source = null;
var resolver = null;
try {
parser =
cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
resolver =
cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
source = resolver.resolveURI(uri);
var is = new
Packages.org.xml.sax.InputSource(source.getInputStream());
is.setSystemId(source.getURI());
return parser.parseDocument(is);
} finally {
if (source != null)
resolver.release(source);
cocoon.releaseComponent(parser);
cocoon.releaseComponent(resolver);
}
}
Regards,
--------------------
Luca Morandini
www.lucamorandini.it
--------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Re: Getting XML data into Flowscript
Posted by ho...@armacell.com.
Is loadDocument(String) a function that you implemented? I only got an
error message.
Any hint appreciated
Regards
Holger
news <ne...@sea.gmane.org> schrieb am 06.02.2006 09:41:44:
> holger.willenborg@armacell.com wrote:
> >
> > I am trying to extract data from a XML source (XML file or Cocoon
> > pipeline) for use in a flowscript (actually it's an XML file
containing
> > quiz questions and the correct answers. I need to extract the answers
to
> > test if the user selected the correct choice).
> >
> > Any ideas?
>
> Sure, you may use JXPath, like in:
>
> importClass(Packages.org.apache.commons.jxpath.JXPathContext);
>
> var collDoc= loadDocument("tmp/complete-" + locale +".wmcd");
> var collCtx=
> Packages.org.apache.commons.jxpath.JXPathContext.newContext(collDoc);
> var boundingBoxCtx=
> Packages.org.apache.commons.jxpath.JXPathContext.newContext(
> collCtx,
>
collCtx.selectSingleNode("/collection/interface/General/Window/BoundingBox")
> );
> var srs= boundingBoxCtx.getValue("@SRS");
>
> Regards,
>
> --------------------
> Luca Morandini
> www.lucamorandini.it
> --------------------
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
Re: Getting XML data into Flowscript
Posted by Luca Morandini <lm...@ieee.org>.
holger.willenborg@armacell.com wrote:
>
> I am trying to extract data from a XML source (XML file or Cocoon
> pipeline) for use in a flowscript (actually it's an XML file containing
> quiz questions and the correct answers. I need to extract the answers to
> test if the user selected the correct choice).
>
> Any ideas?
Sure, you may use JXPath, like in:
importClass(Packages.org.apache.commons.jxpath.JXPathContext);
var collDoc= loadDocument("tmp/complete-" + locale +".wmcd");
var collCtx=
Packages.org.apache.commons.jxpath.JXPathContext.newContext(collDoc);
var boundingBoxCtx=
Packages.org.apache.commons.jxpath.JXPathContext.newContext(
collCtx,
collCtx.selectSingleNode("/collection/interface/General/Window/BoundingBox")
);
var srs= boundingBoxCtx.getValue("@SRS");
Regards,
--------------------
Luca Morandini
www.lucamorandini.it
--------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Antwort: Re: Getting XML data into Flowscript
Posted by Brian Maddy <bm...@kampersoftware.com>.
Oops, I wish I had been playing closer attention to the list. I would
have posted this sooner. I was trying to get this to work a while
back. Here's how someone in the cocoon chat room showed me how to do it:
// Get our xml string that tells our totals
var output = new Packages.java.io.ByteArrayOutputStream();
cocoon.processPipelineTo("searchTotals",
{where_definition:where_definition}, output);
// build a document to parse
var parser =
cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
var sr = new Packages.java.io.StringReader(output.toString())
var is = new Packages.org.xml.sax.InputSource(sr);
var doc = parser.parseDocument(is);
var context =
Packages.org.apache.commons.jxpath.JXPathContext.newContext(doc);
// do an xpath query to get some info
var developmentCount = context.getValue("//sql:developments[1]");
Is this what you guys are looking for?
Brian
holger.willenborg@armacell.com wrote:
>
> Found some hints on that here:
> http://wiki.apache.org/cocoon/EndorsedLibsProblem
>
> I'll post the results.
>
> Thanks so far.
>
> Regards
> Holger
>
> users-return-85070-holger.willenborg=armacell.com@cocoon.apache.org
> schrieb am 06.02.2006 21:53:29:
>
> >
> > I get an error:
> > javax.xml.transform.dom.DOMResult.getNextSibling()Lorg/w3c/dom/Node;
> >
> > Have you seen that one, too? Any help appreciated.
> >
> > Regards
> > Holger
> >
> > users-return-85060-holger.willenborg=armacell.com@cocoon.apache.org
> > schrieb am 06.02.2006 09:38:29:
> >
> > > What I use to get XML data (DOM) from a pipeline from flowscript is :
> > >
> > > var pipe = cocoon.createObject(org.apache.cocoon.components.flow.
> > > util.PipelineUtil);
> > > var doc = pipe.processToDOM("some/pattern", {});
> > >
> > > see PipelineUtil javadoc for other usages.
> > >
> > > laurent
> > >
> > >
> > > 2006/2/6, holger.willenborg@armacell.com
> <ho...@armacell.com>:
> > > >
> > > > Hi,
> > > >
> > > > I am trying to extract data from a XML source (XML file or
> > Cocoon pipeline)
> > > > for use in a flowscript (actually it's an XML file containing quiz
> > > > questions and the correct answers. I need to extract the
> answersto test if
> > > > the user selected the correct choice).
> > > >
> > > > Any ideas?
> > > >
> > > > Regards
> > > > Holger
> > >
> > >
> > > --
> > > <a href="http://in-pocket.blogspot.com">http://in-pocket.blogspot.com
> > > - Mobile world, technology and more</a>
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > > For additional commands, e-mail: users-help@cocoon.apache.org
> > >
> > >
Antwort: Re: Getting XML data into Flowscript
Posted by ho...@armacell.com.
Yep, now it works.
Thanks for all.
Regards
Holger
users-return-85073-holger.willenborg=armacell.com@cocoon.apache.org
schrieb am 06.02.2006 22:29:37:
>
> Found some hints on that here: http://wiki.apache.
> org/cocoon/EndorsedLibsProblem
>
> I'll post the results.
>
> Thanks so far.
>
> Regards
> Holger
>
> users-return-85070-holger.willenborg=armacell.com@cocoon.apache.org
> schrieb am 06.02.2006 21:53:29:
>
> >
> > I get an error:
> > javax.xml.transform.dom.DOMResult.getNextSibling()Lorg/w3c/dom/Node;
> >
> > Have you seen that one, too? Any help appreciated.
> >
> > Regards
> > Holger
> >
> > users-return-85060-holger.willenborg=armacell.com@cocoon.apache.org
> > schrieb am 06.02.2006 09:38:29:
> >
> > > What I use to get XML data (DOM) from a pipeline from flowscript is
:
> > >
> > > var pipe = cocoon.createObject(org.apache.cocoon.components.flow.
> > > util.PipelineUtil);
> > > var doc = pipe.processToDOM("some/pattern", {});
> > >
> > > see PipelineUtil javadoc for other usages.
> > >
> > > laurent
> > >
> > >
> > > 2006/2/6, holger.willenborg@armacell.com
<ho...@armacell.com>:
> > > >
> > > > Hi,
> > > >
> > > > I am trying to extract data from a XML source (XML file or
> > Cocoon pipeline)
> > > > for use in a flowscript (actually it's an XML file containing
quiz
> > > > questions and the correct answers. I need to extract the
> answersto test if
> > > > the user selected the correct choice).
> > > >
> > > > Any ideas?
> > > >
> > > > Regards
> > > > Holger
> > >
> > >
> > > --
> > > <a
href="http://in-pocket.blogspot.com">http://in-pocket.blogspot.com
> > > - Mobile world, technology and more</a>
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > > For additional commands, e-mail: users-help@cocoon.apache.org
> > >
> > >
Antwort: Re: Getting XML data into Flowscript
Posted by ho...@armacell.com.
Found some hints on that here:
http://wiki.apache.org/cocoon/EndorsedLibsProblem
I'll post the results.
Thanks so far.
Regards
Holger
users-return-85070-holger.willenborg=armacell.com@cocoon.apache.org
schrieb am 06.02.2006 21:53:29:
>
> I get an error:
> javax.xml.transform.dom.DOMResult.getNextSibling()Lorg/w3c/dom/Node;
>
> Have you seen that one, too? Any help appreciated.
>
> Regards
> Holger
>
> users-return-85060-holger.willenborg=armacell.com@cocoon.apache.org
> schrieb am 06.02.2006 09:38:29:
>
> > What I use to get XML data (DOM) from a pipeline from flowscript is :
> >
> > var pipe = cocoon.createObject(org.apache.cocoon.components.flow.
> > util.PipelineUtil);
> > var doc = pipe.processToDOM("some/pattern", {});
> >
> > see PipelineUtil javadoc for other usages.
> >
> > laurent
> >
> >
> > 2006/2/6, holger.willenborg@armacell.com
<ho...@armacell.com>:
> > >
> > > Hi,
> > >
> > > I am trying to extract data from a XML source (XML file or
> Cocoon pipeline)
> > > for use in a flowscript (actually it's an XML file containing quiz
> > > questions and the correct answers. I need to extract the answersto
test if
> > > the user selected the correct choice).
> > >
> > > Any ideas?
> > >
> > > Regards
> > > Holger
> >
> >
> > --
> > <a href="http://in-pocket.blogspot.com">http://in-pocket.blogspot.com
> > - Mobile world, technology and more</a>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> >
> >
Antwort: Re: Getting XML data into Flowscript
Posted by ho...@armacell.com.
I get an error:
javax.xml.transform.dom.DOMResult.getNextSibling()Lorg/w3c/dom/Node;
Have you seen that one, too? Any help appreciated.
Regards
Holger
users-return-85060-holger.willenborg=armacell.com@cocoon.apache.org
schrieb am 06.02.2006 09:38:29:
> What I use to get XML data (DOM) from a pipeline from flowscript is :
>
> var pipe = cocoon.createObject(org.apache.cocoon.components.flow.
> util.PipelineUtil);
> var doc = pipe.processToDOM("some/pattern", {});
>
> see PipelineUtil javadoc for other usages.
>
> laurent
>
>
> 2006/2/6, holger.willenborg@armacell.com
<ho...@armacell.com>:
> >
> > Hi,
> >
> > I am trying to extract data from a XML source (XML file or Cocoon
pipeline)
> > for use in a flowscript (actually it's an XML file containing quiz
> > questions and the correct answers. I need to extract the answers to
test if
> > the user selected the correct choice).
> >
> > Any ideas?
> >
> > Regards
> > Holger
>
>
> --
> <a href="http://in-pocket.blogspot.com">http://in-pocket.blogspot.com
> - Mobile world, technology and more</a>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
Re: Getting XML data into Flowscript
Posted by Laurent Perez <ha...@gmail.com>.
What I use to get XML data (DOM) from a pipeline from flowscript is :
var pipe = cocoon.createObject(org.apache.cocoon.components.flow.util.PipelineUtil);
var doc = pipe.processToDOM("some/pattern", {});
see PipelineUtil javadoc for other usages.
laurent
2006/2/6, holger.willenborg@armacell.com <ho...@armacell.com>:
>
> Hi,
>
> I am trying to extract data from a XML source (XML file or Cocoon pipeline)
> for use in a flowscript (actually it's an XML file containing quiz
> questions and the correct answers. I need to extract the answers to test if
> the user selected the correct choice).
>
> Any ideas?
>
> Regards
> Holger
--
<a href="http://in-pocket.blogspot.com">http://in-pocket.blogspot.com
- Mobile world, technology and more</a>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org