You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Aurélien DEHAY <ad...@zorel.org> on 2005/05/01 23:06:08 UTC
parsing xml in flowscript.
Hi list.
I'm trying to parse an xml stream from a pipeline result in flowscript.
I've got the following code:
var stream = new java.io.ByteArrayOutputStream;
cocoon.processPipelineTo("etape2", {"url": url}, stream );
var document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(stream);
The "etape2" result is something like this:
<?xml version="1.0" encoding="utf-8"?><infos>
<type>RSS 2.0</type>
</infos>
Cocoon raise an error:
java.net.MalformedURLException: no protocol: <?xml version="1.0" encoding="utf-8"?><infos>
<type>RSS 2.0</type>
</infos>
I can see the following stack trace in Cocoon error.log:
Caused by: java.net.MalformedURLException: no protocol: <?xml version="1.0" encoding="utf-8"?><infos>
<type>RSS 2.0</type>
</infos>
at java.net.URL.<init>(URL.java:567)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
2 questions then:
* Why parse(String uri) is taken rather than parse(InputStream
is)?
* Is there a better way to set infos in pipeline and retrieve them
in flow script (the idea is to get a external stream with
cincluden transform it with xsl and retrieve, for example, the
type of a syndiction (rss/atom/etc.).
Regards.
--
Aurélien DEHAY http://zorel.org
http://logicielslibres.info
Re: parsing xml in flowscript.
Posted by Aurélien DEHAY <ad...@zorel.org>.
Ugo Cei wrote:
[snip]
> Because a ByteArrayOutputStream is not an InputStream. Try;
>
> var is = new ByteArrayInputStream(stream.toByteArray());
> ....parse(is);
It works, thank you.
Regards.
--
Aurélien
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: parsing xml in flowscript.
Posted by Ugo Cei <ug...@apache.org>.
Il giorno 01/mag/05, alle 23:06, Aurélien DEHAY ha scritto:
> I'm trying to parse an xml stream from a pipeline result in flowscript.
> I've got the following code:
>
> var stream = new java.io.ByteArrayOutputStream;
> cocoon.processPipelineTo("etape2", {"url": url}, stream );
> var document =
> DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(stream)
> ;
>
> 2 questions then:
> * Why parse(String uri) is taken rather than parse(InputStream
> is)?
Because a ByteArrayOutputStream is not an InputStream. Try;
var is = new ByteArrayInputStream(stream.toByteArray());
....parse(is);
HTH,
Ugo
--
Ugo Cei
Tech Blog: http://agylen.com/
Source.zone: http://sourcezone.info/
Wine & Food Blog: http://www.divinocibo.it/