Listing XML document canonically

Posted by tom July 13th, 2006

For a project I needed to list for XML documents all it’s nodes in a canonical style. This is how I used Ruby to do it, save the file as listcanonical.rb.


require ‘rubygems’
require ‘xml/libxml’

	

file = ARGV[0] if file "" || file nil puts “Usage: ruby listcanonical.rb ” exit 0 end

doc = XML::Document.file(‘response.xml’) root = doc.root

doc.find(’//*’).each do |node| puts node.path end

Leave a Reply