Created
May 16, 2011 14:24
-
-
Save warlley/974523 to your computer and use it in GitHub Desktop.
Exemplo de busca e leitura de arquivos xml
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
#!/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