-
-
Save denisnurboja/f459220991e7e81603163a3d1b53260a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
require 'nokogiri' | |
xml = File.read('hello.xml') | |
doc = Nokogiri::XML(xml) | |
all_the_things = [] | |
doc.xpath('//file').each do |file| | |
title = file.xpath("./title").first.text | |
filename = file.xpath("./name").first.text | |
identifier = file.xpath("./identifier/*[contains(text(), 'My display ID')]").text | |
secret = file.xpath("./identifier/secret").attr('secret').text | |
all_the_things << [title, filename, identifier, secret] | |
end | |
CSV.open('new_file.csv', 'wb' ) do |row| | |
row << ['title', 'filename', 'identifier', 'secret'] | |
all_the_things.each do |data| | |
row << data | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment