Discussion:
[XOM-interest] Visitor pattern: could be nice addon for the library
Dmitry Katsubo
2010-03-27 12:19:58 UTC
Permalink
Dear XOM developers and XOM users!

I would like to share with you my opinion about the functionality I miss
in XOM library and also some piece of code, that somebody might find
useful. Maybe they already exist in the library, but I refer the latest
one available in Maven (v1.1)

First of all, I have read the authors view on Visitors [1] and I find it
reasonable: maybe it does not make sense to push all algorithms into
Node or Document class. However, I think some algorithms are very basic
and demanded very often in XML-manipulation libraries. This is mainly
tree traversal with additional functionality on the top:
- Find a node with a given ID
- Find nodes with a given name
- Find a node with some conditions which are not known in advance
(defined in some closure).

I also have read few posts into this maillist ([2,3]) and I also see the
demand of custom serialization of nodes.

I believe that having these algorithms somewehre in a separate XMLUtils
class as static helpers will not harm. I think, this is good practice,
as shown by java.util.Collections and java.util.Arrays classes.

I attach the example of Java class, that I had to program on the top of
XOM library to satisfy my demands. Maybe someone find it helpful. The
example demonstrates also how the Visitor pattern can benefit from
generics. The same way one can generalize optional exception that is
allowed to be thrown by the visitor.

Any feedback or opinion is welcome.

[1] http://www.xom.nu/faq.xhtml#d0e373
[2] http://lists.ibiblio.org/pipermail/xom-interest/2006-March/002897.html
[3]
http://lists.ibiblio.org/pipermail/xom-interest/2002-September/000077.html
--
With best regards,
Dmitry


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: PackagePanel.java
Url: http://lists.ibiblio.org/pipermail/xom-interest/attachments/20100327/86906948/attachment.pl
Loading...