Hi,
Thanks for this nice overview. I am happy that XML handling gets a bit more traction in
Smalltalk :). I took a quick look and your XMLPluggableElementFactory sounds quite
interesting, and it's great that it supports namespaces.
Regarding Opax, your analysis is not quite right.
- You do not need to subclass the OPOpaxHandler.
- The goal of Opax is not to replace DOM, but to enhance SAX. It's true that at the
moment it still creates a tree, but this should be changed to make it optional. The
original idea of Opax was to dispatch everything, including the factory decision to the
Element, but the implementation remained behind the wishes.
- Opax is tiny: 3 classes + 4 test classes
- OPGenericElement should simply be made a subclass of XMLElement, and we would have the
compatibility we would need.
- I do not see the reasons why DOM should be preferred to SAX. The problem with DOM is
that it always creates XML elements :). When you have large XML files, you often do not
want to load them, but just to process them directly. This is the goal of SAX, but then
SAX is procedural. Opax should be used to transform SAX into an object-oriented handling.
Instead of removing it, I would suggest a different approach. Let's make it focus on
the SAX parsing:
- We could easily get it to use the XMLNodeFactory
- We could subclass OPGenericElement from XMLElement.
In any case, regarding packaging, I would definitely be in favor of splitting XMLSupport
in multiple packages.
Cheers,
Doru
On 15 Nov 2010, at 08:46, jaayer wrote:
The most recent version of XML-Support comes with a
factory-based abstraction layer to customize the node object construction done by the
parser. The default factory is just a number of stateless accessors with names like
#elementClass and #documentClass that return class objects. This class can be subclassed
and those messages overridden, and the subclass can then be instantiated and injected into
a DOM parser using #nodeFactory: before parsing.
However, also included is a node factory subclass named XMLPluggableElementFactory that
can map specific elements to specific element classes based on the name and namespace
information of the elements in question. Here is an example of its use:
doc := (XMLDOMParser on: aStringOrStream)
nodeFactory:
(XMLPluggableElementFactory new
handleElement: 'user' withClass: MyUserElement;
handleElement: 'report' withClass: MyReportElement;
handleElement: 'report' namespaceURI: 'urn:specialReport' withClass:
MySpecialReportElement);
parseDocument.
This is undoubtedly similar to Opax, if not in its approach then certainly in its intent.
I feel, however, that it is superior to Opax in a number of respects and question whether
Opax should remain in XML-Support.
First, the node factory abstraction layer is based on the DOM parser and XMLNode classes,
not the SAX parser and the custom OP*Element classes Opax has added. This means that users
will get back instances of XMLElement subclasses rather than OPGenericElement subclasses,
and those objects will support the entire XMLElement protocol. Second, the pluggable
element factory enables more powerful element/class mapping based not only on the names of
elements but their namespace information as well. Third, the element factory and its test
are both quite small, in part because they do not need to duplicate the functionality of
XMLElement like OPGenericElement does. Fourth, because the element factory is a subclass
of XMLNodeFacory, it can be subclassed further to exert additional control over which
classes the DOM parser should use for other, non-element nodes. Fifth and perhaps most
important of all, the factory approach does not require a specific subclass of
XMLDOMParser to be used
; it is injected into a DOM parser by the user, so any DOM parser, even ones that already
exist, can use it without modification. To use Opax, however, a parser must be a subclass
of OPOpaxHandler, which is itself a subclass of SAXHandler. That means DOM parsers
can't be used with Opax at all, and existing SAX parsers can't use it unless they
are rewritten to be subclasses of OPOpaxHandler.
I think Opax should be taken out and made optionally loadable by the Metacello
configuration file. In fact, this should be done regardless of which approach is
preferred, as the package is already quite large and stands to get larger as more is
added. I plan on making XMLWriter a separate but required package, and the test suites
separate but optional packages.
If anyone has any objections, I would like to hear them.
_______________________________________________
Moose-dev mailing list
Moose-dev(a)iam.unibe.ch
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
--
www.tudorgirba.com
"We cannot reach the flow of things unless we let go."