velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Rees <dr...@runt.ebetinc.com>
Subject Re: wrapping XML document as JavaBeans?
Date Wed, 03 Oct 2001 01:43:51 GMT
On Tue, Oct 02, 2001 at 09:12:35PM -0400, Geir Magnusson Jr. wrote:
> > 
> > when I'd much rather write:
> > 
> > $field.name
> > 
> > I could create explicit model JavaBean objects, like Torque does, but I
> > might want to deal with lots of different XML documents, and don't want to
> > have to generate a set of JavaBeans for each DTD.
> > 
> > Are there any other options?  Would it be feasible to create a generic
> > wrapper-ojbect that allows <field><name>id</name></field>
to be accessed as
> > "$field.name" ?
> 
> Sure - I would think that's pretty easy if you want simple access.
> 
> For example, implement on your wrapper-object
> 
> Public Object get(String)
> 
> And return the child node (in the same object class).
> 
> $field.name will make velocity call get("name")
> 
> You might also choose to build something path-ish so you can access any
> level...

Yep, you could easily do this using a HashMap so you don't have to write a
custom container, just something to parse/store it:

<object>
  <value>Data</value>
  <some>
    <othervalue>MoreData</othervalue>
  </some>
</object>

object.get("value")
object.get("some/othervalue")

If you have elements with attributes with the same name as lower elements,
things could get tricky, but that's a pooly designed XML spec anyway.  ;-)

-Dave

Mime
View raw message