struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Germuska <>
Subject Re: Struts & XML
Date Wed, 23 Oct 2002 17:18:12 GMT
Of course, the suggestions to check out STXX or the JSTL to use XSLT 
to style your XML are perfectly good...  and maybe that's why you 
decided to change your subroutine to return XML...  but if you want 
to get things back into familiar object-land, you could pass the XML 
to some routine which could produce a java Object for you from the 
XML.  Then you could use the object in Struts in all the usual ways.

There are whole frameworks for this (Betwixt, Zeus, Castor, others) 
but if you only need to consume the XML and never need to write it 
out in the same fashion from the object, you might want to check out 
Jakarta Commons Digester (which is how Struts reads in all of its 
configuration files.)

Once I learned how to use Digester, I never again had a moment's 
pause over the question of whether it was "too much trouble" to use 
an XML file to externalize some data -- it's really easy to use, 
especially if you have the liberty of designing your own XML format, 
in which case you can make things even easier.  Basically, you can 
assign an element name to an object and use attributes of that 
element named exactly as the properties of that object, and you can 
get Digester to construct and populate a bean for you in about three 
lines of code.

See for details; 
there isn't a lot more documentation, but the Javadoc is pretty 

One thing to note is that digesters aren't designed to be threadsafe; 
if you are using digester in a servlet environment, you should keep 
in mind the same considerations as when writing servlets.


At 9:17 AM -0700 2002/10/23, Wendy Smoak wrote:
>Currently I'm calling a database subroutine (in an Action) that returns a
>list of keys, and then using a DAO in a loop to build up a List of Java
>objects that contain the data I need to display.  That List gets put in
>session scope and then it's off to the resolution.jsp to display it with a
><logic:iterate> tag.
>*IF* I changed the database subroutine to return XML, what would I do with
>it?  I'd have something like this coming back:
>  <person>
>   <name>John Smith</name>
>   <birthdate>05/25/1965</birthdate>
>   <status>PP</status>
>   <address>
>       123 State Street
>       City, ST, 12345
>   </address>
>   <source>ALUM</source>
>   <reunion_class>ML1999</reunion_class>
>   <reunion_class>ME2002</reunion_class>
>  </person
>(I'm unclear on how to format the address which has multiple lines.)
>Anyway, would I put that String in session scope?  And then... I'm just
>reading about XSLT now.  Can someone point me in the general direction of
>which Struts (or other) taglibs I might need?  I'm on Tomcat 4.1.12 & a
>recent Struts nightly build with the -el tags.
>Thanks in advance,
>Wendy Smoak

* Joe Germuska    { }
"It's pitiful, sometimes, if they've got it bad. Their eyes get 
glazed, they go white, their hands tremble.... As I watch them I 
often feel that a dope peddler is a gentleman compared with the man 
who sells records."
	--Sam Goody, 1956

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message