cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vadim Gritsenko" <vadim.gritse...@verizon.net>
Subject RE: How do I generate XML in cocoon 2, as in cocoon 1.x?
Date Mon, 11 Feb 2002 16:58:28 GMT
> From: Marko Niinimaki [mailto:man@mail.cern.ch]
> 
> Hello,
> 
> thanks for the answer (please see below)
> 
> On Mon, 11 Feb 2002, Vadim Gritsenko wrote:
> 
> > In Cocoon 2.X, no xspParser is in XSPGenerator. IIRC, this was not
> > heavily advertised in Cocoon 1.X also. So if you need a parser it's
now
> > your responsibility now to lookup it from the component manager and
> > release it (don't forget to release, best place is finally
statement).
> >
> > Then, I see couple of ways:
> >
> > 1. SAX: Use EmbeddedXMLPipe between this.contentHandler and parser
to
> > filter out start/end document.
> > 2. DOM: Parse string as DOM and then stream the DOM to the
> > this.contentHandler using DOMStreamer.
> 
> Ok, I cooked up (on the basis of the view-source example) the
following,
> my sitemap states that this is a serverpage and simple-page2html.xsl
> is used to transform it. But the output to the browser is just
> the match of "page". If I try to match "foo", nothing comes out.
> Is there an apparent mistake in the code? Or a tool by which I can
> see the DOM tree of the xsp?
> 
> 
> <?xml version="1.0"?>
> 
> <xsp:page language="java"
>   xmlns:xsp="http://apache.org/xsp"
> >
> <xsp:structure>
>    <xsp:include>java.net.*</xsp:include>
>    <xsp:include>org.w3c.dom.*</xsp:include>
>    <xsp:include>org.apache.cocoon.xml.dom.DOMStreamer</xsp:include>
>    <xsp:include>org.apache.cocoon.xml.dom.DOMBuilder</xsp:include>
>
<xsp:include>org.apache.cocoon.components.parser.Parser</xsp:include>
>
<xsp:include>org.apache.cocoon.components.url.URLFactory</xsp:include>
> </xsp:structure>
> <page>
> <xsp:logic><![CDATA[
> String s = "<foo>yo</foo>";
> Parser newParser = null;
> try {
>  newParser = (Parser) this.manager.lookup(Parser.ROLE);
>  Document document = newParser.newDocument();
>  DOMBuilder builder = new DOMBuilder(newParser);
>  newParser.setContentHandler(builder);
>  InputSource is = new InputSource(new StringReader(s));
>  newParser.parse(is);
>  DOMStreamer ds = new DOMStreamer (this.contentHandler);
>  ds.stream (newParser.parseDocument(is));

Why you parse it twice? Can't you just do something like:

parser.setContentHandler(new EmbeddedXMLPipe(this.contentHandler));
parser.parse(new InputSource(new StringReader(s)))

?

Also, if you need to debug this, you can use:
1. XML serializer right after severpages generator to view XML as
produced by page, or LoggingTransformer after serverpages generator
2. LoggingContentHandler

Vadim

> } catch (Exception e) {
>  System.out.println(e);
> } finally {
>   this.manager.release((Component) newParser);
> }
> ]]>
> </xsp:logic>
> </page>
> </xsp:page>


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

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


Mime
View raw message