> 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: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>