cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Curdt <tcu...@dff.st>
Subject Re: XML parsing inside XSP
Date Wed, 02 Jan 2002 12:21:52 GMT
> Hi all,
>
> I want to be able to parse a java string to an xml representation in a XSP.
> Looking at the source code for the StreamGenerator (which takes a http-post
> stream) i have written the following code to parse a xml string in xsp:
>
>         Parser parser = null;
>         try {
>           org.xml.sax.InputSource inputSource = new org.xml.sax.InputSource(
>             new StringReader(xmldata)
>           );
>           this.getLogger().debug("Looking up parser");
>           parser = (Parser)this.manager.lookup(Parser.ROLE);
>           parser.setContentHandler(this.contentHandler);
>           parser.setLexicalHandler(this.lexicalHandler);
>           parser.parse(inputSource);
>         } catch (Exception ex) {
>           ex.printStackTrace();
>           this.getLogger().debug(ex.getMessage());
>         } finally {
>           if (parser != null) {
>             this.getLogger().debug("Releasing parser");
>             this.manager.release((Component)parser);
>           }
>         }

Be careful. The above will break the XSP SAX structure.
You need to think of the events:

    -xsp:startDocument
     -xsp:startElement
     -xsp:endElement
     - ... some more ...
       // now your code
       -parser:startDocument
        -xsp:startElement
        -xsp:endElement
        - ... some more ...
       -parser:endDocument
    -xsp:endDocument

You see?! start/end Document will be called twice.
This is illegal! Wrapp the page ContentHandler
inside a org.apache.cocoon.xml.EmbeddedXMLPipe before
passing it to the parser.
--
Torsten


---------------------------------------------------------------------
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