-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ross Bamford wrote:
> Hi,
> 
> I've today committed changesets including Mark Van Holstyn's patches, an  
> additional patch I received from Tim Yamin, and a few small fixups and  
> extra tests. These fix bugs in XML::Node#content, and add several  
> convenience methods to Node and Node::Set as previously discussed, as well  
> as defining node equality based on the XML representation.

does this mean? node1 === node2

> 
> I am now considering implementing callback procs for the SAX parser, and  
> would appreciate any ideas anyone might have. Currently I'm looking at two  
> choices:
> 
>       1) Having methods for each callback supported by libxml, which
>          work like set_trace_func:
> 
>               saxparser.set_begin_document(lambda { |...| })
>               saxparser.set_begin_element(lambda { |...| })
>               # ...

I seem to be a fan of the on_* naming convention for callbacks, since the 
terminology "on" itself seems to show that somethng will
happen. And I like just passing blocks.

  saxparser.on_begin_document { |doc| ... }

  # callback for all elements
  saxparser.on_begin_element { |node| ... }

  # callback for only the elements which are "mynode"s
  saxparser.on_begin_element( "mynode" ) { |mynode| ... }


> 
>       2) Introducing a new class (maybe XML::SaxParser::Callbacks?)
>          that provides the above API, and then having e.g.:
> 
>               saxparser.set_callbacks(the_callbacks)
> 
>          This could also have an alternate API, e.g:
> 
>               the_callbacks[:begin_document] = lambda { |...| }
>               the_callbacks[:begin_element] = lambda { |...| }

I think the above api adjustment will get rid of this need. With the above api 
I think it is more readable to. Even if you have a
long callback method

  begin_element_proc = lambda{ |node|
    # a few lines long
    # a few lines long
    # few lines long
    # etc...  }

  saxparser.on_begin_element { |node| being_element_proc.call node }

Seems more readable then:

  begin_element_proc = lambda{ |node|
    # a few lines long
    # a few lines long
    # few lines long
    # etc...  }

  # ... somewhere else in code
  hsh ||= {}
  hsh[ :begin_element ] = begin_element_proc

   #... somewhere else in code
   saxparser.set_callbacks hsh

To me it apperas more readable because you see what on_begin_element is doing 
upfront, rather then having to find the declaration
of the data structure you use when you pass it into 'set_callbacks', and then 
tracking down where you actually assign the
lambda/proc to your data structure.

just my 2 cents

Zach



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFEPS8WMyx0fW1d8G0RAgLvAJ92nFcET1HV8t9iiGB+hkl4sirb9QCdGLha
CtM+/osdUvr4Kzv/4Z3HbWQ=
=cc0a
-----END PGP SIGNATURE-----
_______________________________________________
libxml-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to