... and more interesting.
I am past the set-up phase and I got to the point of building a SAX parser (I have not figured out yet what is the practical difference between SAX and StAX).
My beef with XML is obviously increasing :) But let's not go there. Here is my thinking.
I write SAX:START-ELEMENT methods and let each one of them look like
(defmethod sax:start-element ((h smbl-handler) namespace-uri (local-name (equal "model")) qname attributes) ...)
(defmethod sax:start-element ((h smbl-handler) namespace-uri (local-name (equal "compartment")) qname attributes) ...)
You get the idea... Of course, we don't have EQUAL specializers (and I don't want to depend on "predicate dispatching" extensions :) ) so I did the following trick.
(defclass sbml-parser (sax:sax-parser) ; Why do I need this? () )
(defclass sbml-handler (sax:default-handler) ((source :reader sbml-handler-source :initarg :source) (pathname :reader sbml-handler-pathname :initarg :pathname) ) )
(defclass sbml-symbolizer (cxml:sax-proxy) ())
... and ...
(defmethod sax:start-element ((h sbml-symbolizer) namespace-uri local-name qname attributes) (sax:start-element (cxml:proxy-chained-handler h) (intern namespace-uri) (intern local-name) (intern qname) attributes) )
So now I can write
(defmethod sax:start-element ((h smbl-handler) (namespace-uri (eql '|http://www.smbl.org/sbml/level2/version4%7C)) (local-name (eql '|compartment|)) qname attributes) ...)
apart from the details... Do you guys think this is a sensible approach? It'd make writing the SAX parser a cinch.
Thanks
-- Marco Antoniotti