I wanted to try out libxml instead of nokogiri to see if its any better to parse XML files. Here's a quick program that parses the ISO codes and converts it to a csv file.
Let's say your file has the following XML structure (taken from debian ISO 3166_2 codes)
<iso_3166_2_entries>
<iso_3166_country code="AD">
<iso_3166_subset type="Parish">
<iso_3166_2_entry code="AD-07" name="Andorra la Vella" />
<iso_3166_2_entry code="AD-02" name="Canillo" />
.
.
.
</iso_3166_subset>
</iso_3166_country>
</iso_3166_2_entries>
And you want to convert it to a CSV file of type Country|Type|Name....
require 'rubygems'
Let's say your file has the following XML structure (taken from debian ISO 3166_2 codes)
<iso_3166_2_entries>
<iso_3166_country code="AD">
<iso_3166_subset type="Parish">
<iso_3166_2_entry code="AD-07" name="Andorra la Vella" />
<iso_3166_2_entry code="AD-02" name="Canillo" />
.
.
.
</iso_3166_subset>
</iso_3166_country>
</iso_3166_2_entries>
require 'rubygems'
require 'open-uri'
require 'xml'
# You can also grab the raw XML from http source (see below)
# raw_xml = open("http://somewebsite.myfile=.xml").read
# Here we are grabbing the xml from file source
source = XML::Parser.file('myfile.xml')
content = source.parse
countries = content.root.find('./iso_3166_country')
countries.each do |country|
# Dont process empty or blank countries
if(country.children.first != nil && country.inner_xml.strip != '')
subsets = country.find('iso_3166_subset')
subsets.each do |subset|
entries = subset.find('iso_3166_2_entry')
entries.each do |entry|
code = entry.attributes['code']
name = entry.attributes['name']
# output a tsv
puts country.attributes['code'].strip + "\t" + subset.attributes['type'].strip + "\t" +
code.slice(code.index('-')+1..code.length).strip + "\t" + name.strip
end
end
end
end
perde modelleri
ReplyDeleteMOBİL ONAY
Turkcell mobil ödeme bozdurma
nft nasıl alınır
ankara evden eve nakliyat
trafik sigortasi
Dedektör
Site Kurma
Ask Kitaplari
lisans satın al
ReplyDeleteen son çıkan perde modelleri
uc satın al
minecraft premium
en son çıkan perde modelleri
yurtdışı kargo
nft nasıl alınır
özel ambulans
Good content. You write beautiful things.
ReplyDeletesportsbet
vbet
sportsbet
korsan taksi
taksi
mrbahis
hacklink
mrbahis
vbet
dijital kartvizit
ReplyDeletereferans kimliği nedir
binance referans kodu
referans kimliği nedir
bitcoin nasıl alınır
resimli magnet
7V3K7P
hatay
ReplyDeletekars
mardin
samsun
urfa
5İAT
df
ReplyDeleteرقم مصلحة المجاري بالاحساء bjG1jWupAq
ReplyDeleteشركة مكافحة الحشرات بالاحساء iEp8FQn41U
ReplyDelete