#!/usr/bin/env ruby require 'nokogiri' require 'json' hash = Hash.new begin Dir.open(".").each do | name | next unless name.match('.xml$') next if File.size(name) == 0 doc = Nokogiri::XML(File.open(name)) begin doc.xpath('///c:Name').each do |the| hash['FamilyName'] = the.xpath('c:FamilyName').text hash['GivenName'] = the.xpath('c:GivenName').text end rescue # puts "error #{$!.inspect}" end num = 1 doc.xpath('////c:PhoneNumber').each do |the| hash["Number#{num}"] = the.xpath('c:Number').text num += 1 end end rescue Exception => e # puts "error #{$!.inspect}" # puts e.backtrace.join("\n") end puts hash.to_json #EOF