You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Dhulipala, Kris (SCI TW)" <Kr...@stercomm.com> on 2003/04/04 17:51:50 UTC

JAXB vs Digester

Hi,
  From what I have seen of JAXB and Digester, both fecilitate xml-> java
class/object conversion and vice-versa. So what is the difference? When to
use what?
Thanks,
Kris

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: JAXB vs Digester

Posted by Arron Bates <st...@keyboardmonkey.com>.
> > Subject: JAXB vs Digester
> >
> > Hi,
> >   From what I have seen of JAXB and Digester, both fecilitate xml-> java
> > class/object conversion and vice-versa. So what is the difference? When to
> > use what?
> 
> A couple of very incomplete thoughts:
> 
> * Digester is one way (XML->Java), JAXB is two way (XML->Java
>   and Java->XML).
> 
> * Digester is nice for pulling just a few things out of an XML
>   document, JAXB typically wants you to process the whole thing.
> 
> * Digester rules can be calculated and constructed on the fly
>   as you configure the Digester, and include some interesting 
> matching  rules that mean you don't always need to understand the entire
>   document structure.  JAXB is more like DOM, giving you a tree
>   structure to process.
> 
> * Digester lets you deal with dynamic sets of attributes gracefully
>   (i.e. the SetPropertiesRule, for example); JAXB wants you to know
>   them ahead of time.
> 
> As with most things, it's kind of hard to say that one approach is always
> going to be better or worse; thinking through both approaches for 
> each use case is probably the best approach -- in particular, I'd 
> implement a couple of simple use cases both ways to see which one 
> appeals to you more.


>From the horse's mouth.
(Not that Craig's a horse, very nice chap. But I have heard that he has a salt
lick in his cubicle :).

Anyways...
If you're comfy with XMLSchema, JAXB's a truly handy thing. Configure all the
element types into the xsd, and if the inbound XML is only one of those types,
then it will return that object. Very handy.

As it stands, digester's only drawback is it's inbound XMl only, and JAXB's
strength is that it goes both ways. That said, digester's spiffy for config
XML files. Where I find JAXB indispensible, is with VO objects between
application layers. If bound objects are used as the only means of
communicating with the business tier, it means that the server is ready to
dance as an XMl service, all that has to happen is the simple marshaller to
get the XMl into Java objects. Naturally, your own application can just go in
the tradesman's entrance and pass it the java objects directly.

I really dig it. I wish Castor would change ever so slightly to conform to the
spec as I like the internals of its generated objects slightly better, but
it's all good. I've been using the JAXB since the public was able to get at
it, and I'm a happy customer.

Enough rant from me...


Arron.


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: JAXB vs Digester

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 4 Apr 2003, Dhulipala, Kris (SCI TW) wrote:

> Date: Fri, 4 Apr 2003 10:51:50 -0500
> From: "Dhulipala, Kris (SCI TW)" <Kr...@stercomm.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: "'struts-user@jakarta.apache.org'" <st...@jakarta.apache.org>
> Subject: JAXB vs Digester
>
> Hi,
>   From what I have seen of JAXB and Digester, both fecilitate xml-> java
> class/object conversion and vice-versa. So what is the difference? When to
> use what?

A couple of very incomplete thoughts:

* Digester is one way (XML->Java), JAXB is two way (XML->Java
  and Java->XML).

* Digester is nice for pulling just a few things out of an XML
  document, JAXB typically wants you to process the whole thing.

* Digester rules can be calculated and constructed on the fly
  as you configure the Digester, and include some interesting matching
  rules that mean you don't always need to understand the entire
  document structure.  JAXB is more like DOM, giving you a tree
  structure to process.

* Digester lets you deal with dynamic sets of attributes gracefully
  (i.e. the SetPropertiesRule, for example); JAXB wants you to know
  them ahead of time.

As with most things, it's kind of hard to say that one approach is always
going to be better or worse; thinking through both approaches for each use
case is probably the best approach -- in particular, I'd implement a
couple of simple use cases both ways to see which one appeals to you more.

> Thanks,
> Kris

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org