Hi folks,

I was just talking to Harry Lai(a very helpful cocoon user I might add!)
about the problem of outputting XML from Java.

>From my experience, creating an XML output string from Java object is
messy work. As bad as the original problem of outputting HTML content
in Java. Ugly stuff. 

>From his experience, Harry says their group uses Velocity.
He says when they  started their current project, one of their high priority
requirements was finding a clean(er) way of building up XML content.
After some looking around, they decided to use Velocity (wrapped inside
an EJB)
to generate the XML.  And So far, he says they've been very happy with
it (and Cocoon). =) 

I also heard that Castor might be a good solution. 

Can anyone comment or suggest any other good way to transform XMl from
Java?

Thanks,
Phong

PS
I forward you our discussion just in case I left anything out


___________________________________________________________
FREE voicemail, email and fax, all in one place.  Sign Up Now! http://www.alberta.com
--- Begin Message ---
Hi Phong,

Yeah, I totally agree with you about the ugliness of constructing XML in
Java.  When we started our current project, one of our high priority
requirements was finding a clean(er) way of building up XML content.  After
some looking around, we decided to use Velocity (wrapped inside an EJB) to
generate the XML.  If you're not familiar with Velocity, it's a
template-based tool from Apache
(http://jakarta.apache.org/velocity/index.html).  So far, we've been very
happy with it (and Cocoon).  =)

Harry

PS  I'm not familiar with Castor, but I think there's been some discussion
about it on the cocoon-users list.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 15, 2002 12:09 PM
To: Lai, Harry
Subject: RE: Question about best approach to transform Java Object to
XML represention for use in Cocoon


Hi Harry,

Thanks for your quick reply!
What you describe sounds very nice and clean. Exactly what I need. 

But it now leads me to this follow up question. I was hoping the Xmlizable
interface would make it easier for the java object to output xml content.
But from what you tell me, it looks like xmlizable doesn't help generate
the xml at all. only how it is treated by cocoon.

>From my experience, creating an XML output string from Java object is
messy work. As bad as the original problem of outputting HTML content
in Java. Ugly stuff. 
What do you use in your java object to create the XML output? 

I heard Castor might be a good tool to do this.

thanks again for your help.
Phong
xmlSource.getContent();


---- "Lai, Harry" <[EMAIL PROTECTED]> wrote:
> Hi Phong,
> 
> How's it going?  I actually found a simpler solution since I posted
> that
> message (thanks to a post from someone else).  It relies on the util
> logicsheet that comes with Cocoon2.
> 
> So as you probably found, if you just use <xsp:expr> to output xml
> from a
> java object, the xml gets escaped and is treated as text.  However,
> if you
> surround your <xsp:expr> tag with tags from the util logicsheet (example
> below), the xml from your java object is treated as actual xml content.
> Here's an example (assumes you have the util logicsheet declared in
> the
> "util" namespace):
> 
> ...
> <xsp:logic>
>       MyXmlSource xmlSource = new MyXmlSource();
>       
>       ... init xmlSource and do whatever you need to prepare content
> ...
> 
>       String xmlContent = xmlSource.getContent();
> 
>       
>
<util:include-expr><util:expr><xsp:expr>xmlContent</xsp:expr></util:expr></u
> til:include-expr>
> </xsp:logic>
> ...
> 
> If I remember right, the util logicsheet works by using the XMLizable
> object
> underneath, so it's basically a cleaner interface for the approach
> I had
> mentioned previously.  =)  Anyway, hope that helps!
> 
> Harry
> 
> 
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 15, 2002 11:12 AM
> To: [EMAIL PROTECTED]
> Subject: Question about best approach to transform Java Object to XML
> represention for use in Cocoon
> 
> 
> 
> 
> Hi Harry,
> 
> I am working with Cocoon2 and I am trying to sort out  the exact same
> problem you raised a while back in one of the posts you sent to the
> mailing
> list and so I am hoping you can give me some advice. I would like to
> output an xml representation of a Java object so that it can be sent
> to a stylesheet for tranformation into HTML. I include your post to
> the
> mailing list  at the end of this email for your reference.
> 
> Did you have any success with this problem? If you have can you give
> your insight on the best practice approach you would recommend to output
> xml from Java object?
> 
> Is XMLizable the best way to go?  I also read in the mailing archives
> about the Castor Transformer. 
> 
> I originally thought the best way to do this would be to output the
> xml
> in a logicsheet. And so the idea is to pass a Java object into a
logicsheet
> and then you would traverse the java object and output XML using templates
> in the logicsheet. It seemed like a good idea because outputting XML
> tags in a logicsheet is very easy. But what I found is that  logicsheets
> don't handle Java code too well and it gets messy when you start having
> even a little bit of java code in a logic sheet. 
> 
> Anyways, I would be very interested in gaining some insight from your
> experience.
> 
> Also if you recommend the XMLizable approach, could you send me a sample
> showing how it works?  I have looked in vain but cannot see any examples
> or documentation to get me started on this route.
> 
> 
> Thanks,
> Phong
> 
> PS
> Below is your original post
> 
> Hi all,
> 
> Murphy's Law, but I think I've solved our problem a minute after sending
> this out.  Anyway, for those interested, I found that there's an XMLizable
> interface, and if your object returns XMLizable (instead of a String),
> xsp:expr calls your XMLizable's toSAX() method instead of outputting
> your
> return value as a text node.  No changes to cocoon needed.  =)
> 
> Feeling kinda slow on the uptake,
> Harry
> 
> 
> -----Original Message-----
> From: Lai, Harry [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, December 06, 2001 5:58 PM
> To: 'CocoonUsers'
> Subject: Inserting dynamic XML at request time
> 
> 
> Hi all,
>  
> I have a question that's related to the "Inserting / Comining XML data"
> thread, but which I believe is slightly different.  Here's the situation.
>  
> SCENARIO
> -----------------
> We are using Cocoon 2, and we would like to use an XSP doc as a "shell"
> that
> aggregates XML data from one or more Java objects (the objects would
> actually output XML strings).  These Java objects (possibly EJB's)
> would
> need access to the Request object in order to do their processing.
>  So,
> here's what we originally tried (most of you will probably see the
> flaw
> pretty quickly).
>  
> PROBLEM
> ----------------
> We have a Java object like this (this sample is a simplified version
> of what
> we're actually planning to do, but it illustrates the problem we're
> running
> into):
>  
>     public class Foo {
>         public getXML(Request req) {
>             return "<foo>This is a foo tag.</foo>";
>         }
>     }
>  
> And we have this XSP doc:
>  
>     <xsp:page language="java" xmlns:xsp=" http://apache.org/xsp
> <http://apache.org/xsp> ">
> <xsp:structure>
> <xsp:include>com.coremetrics.test.Foo</xsp:include>
> </xsp:structure>
> <xsp:logic>
> Foo f = new Foo();
>         </xsp:logic>
> <page>
> <xsp:expr>f.getXML(request)</xsp:expr>
> </page>
> </xsp:page>
> Unfortunately, <xsp:expr> renders the return value as a text node,
> so
> we got
> the text content "<foo%gt;..." as the content of our page node in
> the
> resulting xml.  SO...
> 
> 
> ___________________________________________________________
> FREE voicemail, email and fax, all in one place.  Sign Up Now!
> http://www.alberta.com
> 

___________________________________________________________
FREE voicemail, email and fax, all in one place.  Sign Up Now!
http://www.alberta.com


--- End Message ---
---------------------------------------------------------------------
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]>

Reply via email to