> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > > Whats the best way to perform marshalling from Objects to XML within XSP's?
Take a look at the XMLizable interface. These objects could be included as easy as (IIRC): <xsp:expr>myXMLizable</xsp:expr> > The Object is a result from a Castor OQL-Query. > Here's an example what I'd like to intend: > > > <some-items anAttr="aVal"> > <xsp:logic> > marshalObjToXml(model.getAnItem()); > </xsp:logic> > </some-items> > > I've experimented in vain with the following approaches: > > 1. Include Object as String: > > > <xsp:page > language="java" > xmlns:xsp="http://apache.org/xsp" > xmlns:cinclude="http://apache.org/cocoon/include/1.0" > xmlns:util="http://apache.org/xsp/util/2.0" > > > <some-items anAttr="aVal"> > <util:include-expr> > <xsp:expr>model.getAnItemAsString()</xsp:expr> > </util:include-expr> > </some-items> > </some-items> > </xsp:page> > > The page does not compile. The method .getAnItemAsString is not even > executed. This will compile if you put everything on one line, no text nodes in the util:include-expr element: <util:include-expr><xsp:expr>model.getAnItemAsString()</xsp:expr></util: include-expr> Also, I would not recommend you this anyway because of re-parsing performance penalty. > 2. > Use Castor's marshalling capabilities: > > <some-items anAttr="aVal"> > <xsp:logic> > model.marshal(this.contentHandler); > </xsp:logic> > </some-items> This sounds perfect. > Within the method I pass the contentHandler (wrapped into > DocumentHandlerAdapter) to castor's marshaller before I perfom mashal(obj). > > As A result the cinclude transformer (which I need) complains about a > Nullpointer exception. Make sure that model.marshal() does not call startDocument() and endDocument() on the contentHandler. If it does, you should strip these calls by wrapping contentHandler into the IncludeXMLConsumer. This should work. Or we have a bug. Vadim > > Does anyone have a better Idea? Examples are welcome. > > Harald > > -- > GMX - Die Kommunikationsplattform im Internet. > http://www.gmx.net --------------------------------------------------------------------- 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]>