From: Bob Gustafson Date: 2001-11-14T06:52:21+09:00 Subject: [ruby-talk:25084] Re: XML support in the standard lib; what exactly? On 14 Nov 2001 06:13:27 +0900 Bob Hutchison wrote: >On 01/11/13 1:41 PM, "Bob Gustafson" wrote: >> >> ---------------------------------- >> >> Striking out on a slightly different direction, maybe some discussion of >> the 'requirements' of a ruby xml processor would be in order. >> >> Requirements - i.e., what do you want to do with the XML documents? > >0) parse an XML document and generate SAX-like events without having to have >the whole document in memory. (I'm getting boring :-) > ... snip Are you interested in having events for 'every' tag in the document, or only a (small) subset? Something like: 1 par = XMLsnip.new(doc_pointer) 2 sn = par.snip('form') 3 sn = par.snip('table') 4 xn = par.snip('a') 5 po = sn.snip('td') 6 po = sn.snip('td') Where each of the snipped pieces are the contents of the next instance of that tag in the snip object? The whole document does not have to be in memory as each 'snip object' contains a pointer to the next character in the snip object. This pointer is incremented as more (sub) objects are found in the object. Thus the objects 'po' in lines 5 and 6 point to different (successive) points in the snip object 'sn', which in turn points to the beginning of a which is after a in the original document. Each snip operation on an object increments the pointer within that object. Thus the snip object xn defined in line 4 points to the beginning of the element after the
element after the element in the original document. This is a pretty dumb way to extract data from XML (actually HTML in my case) web documents, but it works for me in this (limited) usage. 'Works' means that the parser thinking is easily reusable without having to rewrite (re-think) the parser guts. It was quicker to do this than wrap my head around SAX, etc. BobG