[libxml-devel] Proposed API changes for working with child nodes and attributes

Charlie Savage cfis at savagexi.com
Tue Jul 8 13:23:42 EDT 2008


>> Thus node.children is a XML::Node that acts both as a single node and 
>> also a collection.  The same is true for attributes.
> 
> I wanted to revisit this at some point, I'm glad someone is doing it.

Ah good.

>> some_node = doc.find('/foo')
>>
>> child_nodes = some_node.children
>> child_nodes.class == "Array"
>>
>> some_node.each_child do |node|
>>  ... do stuff
>> end
> 
> I think if you go back to the original code from ~0.1, it had an 
> interface like: doc.find('/foo').each {|node| p node }  which was 
> convenient in some situations.  In general, I dislike most of the DOM 
> interfaces available.

Yup, agreed, they are clunky.

> find() should return a set of nodes (I think that's what it does, 
> actually) and the nodeset behaves like the union of a node and an 
> array. 

It does.  I'm tempted to reuse the nodeset, but its fairly tightly tied 
to the XPath code, so its not reusable currently.

  Chaining methods together needlessly to support a DOM interface
> of lists and atoms is a bit clunky and was something I attempted to avoid.

Agreed.

> At this point, "*shrug* whatever."  I think the API for a developer 
> should mask some of the libxml structure of nodesets/nodes because, 
> frankly, it's a pain in the ass. Constantly coding around, "are you a 
> list or a node?" is inefficient and that's largely the value of Ruby - 
> efficiency of programming.

Definitely.

> ...I wonder if I still have my patch hanging around for that makes use 
> of method_missing() to find nodes (pretty cool for XML configuration foo).

Ah, what's that do?

>> And for attributes, I vote that libxml copies REXML's interface:
>>
>> http://www.germane-software.com/software/rexml/doc/classes/REXML/Attributes.html 
>>
>> Thoughts?
> 
> Go for it - attribute support sucked hard.  -sc

Ok - that seems like a place to start.  Also, I've seen people confused 
by how namespaces and attributes work, so I'll add some tests for that.

Charlie
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://rubyforge.org/pipermail/libxml-devel/attachments/20080708/38a56737/attachment.bin>


More information about the libxml-devel mailing list