Skip to content

Instantly share code, notes, and snippets.

@warlley
Created May 16, 2011 14:24
Show Gist options
  • Save warlley/974523 to your computer and use it in GitHub Desktop.
Save warlley/974523 to your computer and use it in GitHub Desktop.
Exemplo de busca e leitura de arquivos xml
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'find'
FIND_PATH = "/Users/warlley/Downloads/nfe"
Find.find(FIND_PATH) do |file_path|
if File.extname(file_path).downcase == '.xml'
nfe = Nokogiri::XML(File.open(file_path))
puts "Data emissao: #{nfe.search('infNFe/ide/dEmi').text}"
puts "Numero NF: #{nfe.search('infNFe/ide/nNF').text}"
puts "CNPJ: #{nfe.search('infNFe/emit/CNPJ').text}"
puts "Chave: #{nfe.search('infNFe').first['Id'].upcase.gsub('NFE', '')}"
puts "Versao: #{nfe.search('infNFe').first['versao']}"
puts "============="
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment