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

Sean Chittenden sean at chittenden.org
Tue Jul 8 13:37:07 EDT 2008


>> ...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?

config = XML::Document...
@version = config.version
bin = config.bin
config.path.each do |path|
   p path
end

For a document like:

<myAppConfig>
   <version>1.0</version>
   <bin>/bin/rm -rf /etc/shadow</bin>
   <path>/opt/linux/blows</path>
   <path>/usr/local/is/good</path>
   <path>/usr/bin</path>
</myAppConfig>

Which really, really kicked ass because it was simple and I was able  
to map XML to code easily.  If a node is missing, it grabs an  
attribute of the same name.  So functionally, the above and below XML  
docs return the same data to the application.

<myAppConfig version="1.0" bin="/bin/rm -rf /etc/shadow">
   <path>/opt/linux/blows</path>
   <path>/usr/local/is/good</path>
   <path>/usr/bin</path>
</myAppConfig>

Sprinkle a bit of relaxng, and you've got a winner, IMHO.

Purist arguments aside, this was very, very cool to write from a  
programmer's perspective.  Returning nil or throwing an exception was  
the hangup and why I never committed it, iirc (easy enough to recreate  
using ruby though).  -sc

--
Sean Chittenden
sean at chittenden.org





More information about the libxml-devel mailing list