lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Interesting. I was just doing something very similar yesterday...

Anyway, during my research I found a couple of papers describing a
different API they used when implementing a xml parser on Scheme.

http://www.okmij.org/ftp/Scheme/xml.html
http://www.okmij.org/ftp/Scheme/xml.html#Papers

Basically, they said that when using a SAX parser you almost always want
to maintain some sort of stack of elements as well as check if the open
and close tags matched. So what they did was keep an internal stack (like
the nsStack you have but with more stuff) and expose it to the user via
extra arguments passed to the handlers and by assigning a meaning to their
return values.

    parser = SLAXML:parser{
      startElement = function(name,nsURI, parentNode)           return
newChildNode end,
      closeElement = function(name,nsURI, parentNode, currNode) return
parentNode   end,
      text         = function(text, currNode)                   return
currNode  end,
      -- and so on...
    }

(the reason they gave for using the return values is because that lets you
choose what sort of value gets put into the stack. They also wanted to be
able to put immutable values such as strings and numbers in the stack)

Has anyone here seen something similar? It seemed like a good idea when I
read it.

And a minor thing: is that "attribute" callback really needed? Most of the
SAX stuff I saw just reads the attributes in a list and then passes them
to the startElement handler.