[cxml-devel] ... and now for something completely different ...

Marco Antoniotti marcoxa at cs.nyu.edu
Fri Apr 22 14:27:10 UTC 2011


... 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|))
                              (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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cxml-devel/attachments/20110422/6900bff4/attachment.html>


More information about the cxml-devel mailing list