From: Tomasz Wegrzanowski Date: 2006-08-05T10:17:05+09:00 Subject: magic/xml library for easy XML processing Hello, Some of you may be interested in a new library for XML processing. It is inspired by languages designed just for XML-processing like CDuce and to some extend by Perl's XML::Twig. Basically easy things should be easy, and everything should be integrated very tightly with Ruby. The code and (rather incomplete) documentation are here -> http://zabor.org/taw/magic_xml/ A few examples, so you can quickly see whether you're interested or not :-) Parse ATOM feed for my blog and prints post titles and URLs: doc = XML.from_url "http://t-a-w.blogspot.com/atom.xml" doc.children(:entry).children(:link) {|c| print "#{c[:title]}\n#{c[:href]}\n\n" if c[:rel] == "alternate" } Get my del.icio.us posts about magic/xml and format them as a XHTML list (for magic/xml's website): deli_passwd = File.read("/home/taw/.delipasswd").chomp url = "http://taw:#{deli_passwd}@del.icio.us/api/posts/recent?tag=taw+blog+magicxml" XML.from_url(url).children(:post).reverse.each_with_index {|p,i| print XML.li("#{i+1}. ", XML.a({:href => p[:href]}, p[:description])) } Extract articles and IDs from a Wikipedia dump. It keeps only small fragments in memory, but provides all convenient access methods (works like XML::Twig, but with much nicer interface): XML.parse_as_twigs(STDIN) {|node| next unless node.name == :page node.complete! t = node.children(:title)[0].contents i = node.children(:id)[0].contents print "#{i}: #{t}\n" } More about stream processing with magic/xml at http://t-a-w.blogspot.com/2006/08/xml-stream-processing-with-magicxml.html The most important thing to do would be to find cases where other libraries are more expressive than magic/xml and fix these cases if possible :-) As I don't know half of the other libraries, and you certainly do, I need your help here :-) And I guess I should also add XPath, port to a faster XML parser (currently using REXML to get a stream of XML parse events), and add some interface for accessing fancy XML features like processing instructions to get it out of alpha :-) -- Tomasz Wegrzanowski [ http://t-a-w.blogspot.com/ ]