commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <simon.kitch...@chello.at>
Subject Re: JAKARTA COMMONS DIGESTER RULES XML PROBLEM
Date Thu, 01 Jan 1970 00:00:00 GMT
---- Kapil Pruthi <kapil.pruthi@gmail.com> schrieb:
> Hi Guys,
> 
> >
> > I have gone through Jakarta digester project and found it too good but
> > there is small info i need for sure to start using this.
> >
> > How do i create XML rules? Don't tell me manually as my data xml is huge.
> > Also i want to use digester for many different cases so obviously i don't
> > prefer to write digester-rules.xml for every case manually.
> >
> > but i want this file to be created somehow...how ???
> > my data xml and java objects are identical in terms of
> > xml tag name <-> Java bean  (one to one mapping)
> >
> > so basically i want to avoid specifying any rules (xml or programmatic) ,
> > how do i do that?
> > Ok lets say i am suppose to use xml rule, then how do i create this huge
> > digester-rules.xml ? any tool to do that ?
> >
> > Any other way to do it >?
> > I have data xml's and corresponding java objects (java field names word to
> > word same as xml tag name)...

Possibly in your case you could define a FactoryCreateRule that is mapped using the pattern
"*", and the corresponding ObjectFactory would just use the tagname as the name of the class
to instantiate. A SetPropertiesRule mapped using the pattern "*" would also handle all the
xml attributes. Whether adding child nodes to the parent can be done with a wildcard rule
depends upon your format; you haven't given an example. but if it can, then that means you
could configure digester with just three rules.

However digester was never really designed for processing input files which have a complete
1:1 mapping to java beans. The strongest feature of Digester is the huge flexibility it offers
when mapping xml to java - which you obviously do not need. And digester is not terribly fast
as it uses a lot of reflection in order to be so flexible.

As your code is so regular, it might be better to just write your own sax-handler to create
and build the appropriate objects. You could possibly use the existing Digester code as inspiration,
but a custom solution would likely be 10 times faster and 10 times smaller as you do not need
a lot of the flexibility that Digester offers.

NB: personally I dislike the xml-rules module. Using the java API to define rules is much
easier.

Regards,

Simon

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


Mime
View raw message