Merhaba arkadaşlar. Bu yazımızda başka bir siteden veri çekmeyi öğreneceğiz. Bu yazıyı hazırlamamda yazrdımcı olan Alper Özaslan‘a buradan teşekkürlerimi iletiyorum.
Verilerini çekeceğimiz sayfa Merkez Bankası’nın kurlarını gösteren sayfa. Eclipse geliştirme ortamında yazdığım projeyi buraya tıklayarak indirebilirsiniz. Özaslan tarafından yazılmış Swing uygulamasını indirmek isteyenler de buraya tıklayarak indirebilir. Uygulamada DOM-Document Object Model (Belge Nesne Modeli) kullanıldı. Şimdi uygulamamızın nasıl çalıştığını, ne yaptığını inceleyelim.
Xml kodlarını düzenlemek için buradaki sayfayı kullanabilirsiniz. Ben merkez bankasınız Xml kodlarını düzenlediğimde şöyle bir sonuç çıktı:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="isokur.xsl"?> <Tarih_Date Tarih="10.09.2014" Date="09/10/2014"> <Currency Kod="USD" CurrencyCode="USD"> <Unit>1</Unit> <Isim>ABD DOLARI</Isim> <CurrencyName>US DOLLAR</CurrencyName> <ForexBuying>2.2022</ForexBuying> <ForexSelling>2.2062</ForexSelling> <BanknoteBuying>2.2007</BanknoteBuying> <BanknoteSelling>2.2095</BanknoteSelling> <CrossRateUSD>1</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="CAD" CurrencyCode="CAD"> <Unit>1</Unit> <Isim>KANADA DOLARI</Isim> <CurrencyName>CANADIAN DOLLAR</CurrencyName> <ForexBuying>2.0007</ForexBuying> <ForexSelling>2.0097</ForexSelling> <BanknoteBuying>1.9933</BanknoteBuying> <BanknoteSelling>2.0173</BanknoteSelling> <CrossRateUSD>1.0992</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="XDR" CurrencyCode="XDR"> <Unit>1</Unit> <Isim>�ZEL �EKME HAKKI</Isim> <CurrencyName>SPECIAL D.RIGHT</CurrencyName> <ForexBuying>3.3054</ForexBuying> <ForexSelling /> <BanknoteBuying /> <BanknoteSelling /> <CrossRateUSD /> <CrossRateOther>1.49961</CrossRateOther> </Currency> <Currency Kod="DKK" CurrencyCode="DKK"> <Unit>1</Unit> <Isim>DAN�MARKA KRONU</Isim> <CurrencyName>DANISH KRONE</CurrencyName> <ForexBuying>0.38215</ForexBuying> <ForexSelling>0.38402</ForexSelling> <BanknoteBuying>0.38188</BanknoteBuying> <BanknoteSelling>0.3849</BanknoteSelling> <CrossRateUSD>5.7537</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="SEK" CurrencyCode="SEK"> <Unit>1</Unit> <Isim>�SVE� KRONU</Isim> <CurrencyName>SWEDISH KRONA</CurrencyName> <ForexBuying>0.30871</ForexBuying> <ForexSelling>0.3119</ForexSelling> <BanknoteBuying>0.30849</BanknoteBuying> <BanknoteSelling>0.31262</BanknoteSelling> <CrossRateUSD>7.1032</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="CHF" CurrencyCode="CHF"> <Unit>1</Unit> <Isim>�SV��RE FRANGI</Isim> <CurrencyName>SWISS FRANK</CurrencyName> <ForexBuying>2.3539</ForexBuying> <ForexSelling>2.369</ForexSelling> <BanknoteBuying>2.3504</BanknoteBuying> <BanknoteSelling>2.3726</BanknoteSelling> <CrossRateUSD>0.9334</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="NOK" CurrencyCode="NOK"> <Unit>1</Unit> <Isim>NORVE� KRONU</Isim> <CurrencyName>NORWEGIAN KRONE</CurrencyName> <ForexBuying>0.34631</ForexBuying> <ForexSelling>0.34864</ForexSelling> <BanknoteBuying>0.34607</BanknoteBuying> <BanknoteSelling>0.34944</BanknoteSelling> <CrossRateUSD>6.3434</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="JPY" CurrencyCode="JPY"> <Unit>100</Unit> <Isim>JAPON YEN�</Isim> <CurrencyName>YEN</CurrencyName> <ForexBuying>2.06</ForexBuying> <ForexSelling>2.0736</ForexSelling> <BanknoteBuying>2.0524</BanknoteBuying> <BanknoteSelling>2.0815</BanknoteSelling> <CrossRateUSD>106.65</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="SAR" CurrencyCode="SAR"> <Unit>1</Unit> <Isim>SUUD� ARAB. R�YAL�</Isim> <CurrencyName>SAUDI RIYAL</CurrencyName> <ForexBuying>0.58717</ForexBuying> <ForexSelling>0.58823</ForexSelling> <BanknoteBuying>0.58277</BanknoteBuying> <BanknoteSelling>0.59264</BanknoteSelling> <CrossRateUSD>3.7505</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="KWD" CurrencyCode="KWD"> <Unit>1</Unit> <Isim>KUVEYT D�NARI</Isim> <CurrencyName>KUWAITI DINAR</CurrencyName> <ForexBuying>7.6374</ForexBuying> <ForexSelling>7.7373</ForexSelling> <BanknoteBuying>7.5228</BanknoteBuying> <BanknoteSelling>7.8534</BanknoteSelling> <CrossRateUSD /> <CrossRateOther>3.4876</CrossRateOther> </Currency> <Currency Kod="AUD" CurrencyCode="AUD"> <Unit>1</Unit> <Isim>AVUSTRALYA DOLARI</Isim> <CurrencyName>AUSTRALIAN DOLL</CurrencyName> <ForexBuying>2.0075</ForexBuying> <ForexSelling>2.0205</ForexSelling> <BanknoteBuying>1.9983</BanknoteBuying> <BanknoteSelling>2.0326</BanknoteSelling> <CrossRateUSD>1.0944</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="EUR" CurrencyCode="EUR"> <Unit>1</Unit> <Isim>EURO</Isim> <CurrencyName>EURO</CurrencyName> <ForexBuying>2.8492</ForexBuying> <ForexSelling>2.8543</ForexSelling> <BanknoteBuying>2.8472</BanknoteBuying> <BanknoteSelling>2.8586</BanknoteSelling> <CrossRateUSD /> <CrossRateOther>1.2938</CrossRateOther> </Currency> <Currency Kod="GBP" CurrencyCode="GBP"> <Unit>1</Unit> <Isim>�NG�L�Z STERL�N�</Isim> <CurrencyName>POUND STERLING</CurrencyName> <ForexBuying>3.5428</ForexBuying> <ForexSelling>3.5612</ForexSelling> <BanknoteBuying>3.5403</BanknoteBuying> <BanknoteSelling>3.5665</BanknoteSelling> <CrossRateUSD /> <CrossRateOther>1.6115</CrossRateOther> </Currency> <Currency Kod="RUB" CurrencyCode="RUB"> <Unit>1</Unit> <Isim>RUS RUBLES�</Isim> <CurrencyName>RUSSIAN ROUBLE</CurrencyName> <ForexBuying>0.0588</ForexBuying> <ForexSelling>0.05957</ForexSelling> <BanknoteBuying /> <BanknoteSelling /> <CrossRateUSD>37.24</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="RON" CurrencyCode="RON"> <Unit>1</Unit> <Isim>RUMEN LEY�</Isim> <CurrencyName>NEW LEU</CurrencyName> <ForexBuying>0.63988</ForexBuying> <ForexSelling>0.64825</ForexSelling> <BanknoteBuying /> <BanknoteSelling /> <CrossRateUSD>3.4223</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="PKR" CurrencyCode="PKR"> <Unit>1</Unit> <Isim>PAK�STAN RUP�S�</Isim> <CurrencyName>RUPEE</CurrencyName> <ForexBuying>0.02147</ForexBuying> <ForexSelling>0.02175</ForexSelling> <BanknoteBuying /> <BanknoteSelling /> <CrossRateUSD>102</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="IRR" CurrencyCode="IRR"> <Unit>100</Unit> <Isim>�RAN R�YAL�</Isim> <CurrencyName>RIAL</CurrencyName> <ForexBuying>0.00822</ForexBuying> <ForexSelling>0.00833</ForexSelling> <BanknoteBuying /> <BanknoteSelling /> <CrossRateUSD>26627</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="CNY" CurrencyCode="CNY"> <Unit>1</Unit> <Isim>��N YUANI</Isim> <CurrencyName>YUAN RENMINBI</CurrencyName> <ForexBuying>0.35727</ForexBuying> <ForexSelling>0.36195</ForexSelling> <BanknoteBuying /> <BanknoteSelling /> <CrossRateUSD>6.1293</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="BGN" CurrencyCode="BGN"> <Unit>1</Unit> <Isim>BULGAR LEVASI</Isim> <CurrencyName>BULGARIAN LEV</CurrencyName> <ForexBuying>1.4485</ForexBuying> <ForexSelling>1.4675</ForexSelling> <BanknoteBuying /> <BanknoteSelling /> <CrossRateUSD>1.5118</CrossRateUSD> <CrossRateOther /> </Currency> <Currency Kod="DEM" CurrencyCode="DEM"> <Isim>ALMAN MARKI</Isim> <CurrencyName>DEUTSCHE MARK</CurrencyName> <CrossRateEuro>1.95583</CrossRateEuro> </Currency> <Currency Kod="BEF" CurrencyCode="BEF"> <Isim>BEL��KA FRANGI</Isim> <CurrencyName>BEL��KA FRANGI</CurrencyName> <CrossRateEuro>40.3399</CrossRateEuro> </Currency> <Currency Kod="LUF" CurrencyCode="LUF"> <Isim>L�KSEMBURG FRANGI</Isim> <CurrencyName>L�KSEMBURG FRANGI</CurrencyName> <CrossRateEuro>40.3399</CrossRateEuro> </Currency> <Currency Kod="ESP" CurrencyCode="ESP"> <Isim>�SPANYOL PEZETASI</Isim> <CurrencyName>�SPANYOL PEZETASI</CurrencyName> <CrossRateEuro>166.386</CrossRateEuro> </Currency> <Currency Kod="FRF" CurrencyCode="FRF"> <Isim>FRANSIZ FRANGI</Isim> <CurrencyName>FRANSIZ FRANGI</CurrencyName> <CrossRateEuro>6.55957</CrossRateEuro> </Currency> <Currency Kod="IEP" CurrencyCode="IEP"> <Isim>�RLANDA L�RASI</Isim> <CurrencyName>�RLANDA L�RASI</CurrencyName> <CrossRateEuro>0.787564</CrossRateEuro> </Currency> <Currency Kod="ITL" CurrencyCode="ITL"> <Isim>�TALYAN L�RET�</Isim> <CurrencyName>�TALYAN L�RET�</CurrencyName> <CrossRateEuro>1936.27</CrossRateEuro> </Currency> <Currency Kod="NLG" CurrencyCode="NLG"> <Isim>HOLLANDA FLOR�N�</Isim> <CurrencyName>HOLLANDA FLOR�N�</CurrencyName> <CrossRateEuro>2.20371</CrossRateEuro> </Currency> <Currency Kod="ATS" CurrencyCode="ATS"> <Isim>AVUSTURYA ��L�N�</Isim> <CurrencyName>AVUSTURYA ��L�N�</CurrencyName> <CrossRateEuro>13.7603</CrossRateEuro> </Currency> <Currency Kod="PTE" CurrencyCode="PTE"> <Isim>PORTEK�Z ESK�DOSU</Isim> <CurrencyName>PORTEK�Z ESK�DOSU</CurrencyName> <CrossRateEuro>200.482</CrossRateEuro> </Currency> <Currency Kod="FIM" CurrencyCode="FIM"> <Isim>F�N MARKKASI</Isim> <CurrencyName>F�N MARKKASI</CurrencyName> <CrossRateEuro>5.94573</CrossRateEuro> </Currency> <Currency Kod="GRD" CurrencyCode="GRD"> <Isim>YUNAN DRAHM�S�</Isim> <CurrencyName>YUNAN DRAHM�S�</CurrencyName> <CrossRateEuro>340.750</CrossRateEuro> </Currency> </Tarih_Date> |
Bu işlemi neden yaptık diye sorarsanız Java’da yazacağımız kod ile değerleri çekeceğiz. Orada hangi isimler ile çekeceğimizi bilmek için Xml kodunu düzenleyip anlamamız gerekiyordu. Bu Xml kodunda her bir döviz Currency etiketi ile oluşturulmuş. Etiketin içinde de CurrencyName,Isim gibi başka etiketler var. Bu değerleri çekeceğiz.
Şimdi verileri çeken Java kodunu inceleyelim. Bu uygulamada asıl işlemi yapan kod TCMBReader sınıfı içindeki getCurrencies metodudur. Bu metot içinde xhtml sayfasında kullanacağımız listeyi oluşturduk ve metot sonunda return ettik. Daha sonra indireceğimiz Xml dosyasını parse ederken kullanacağımız builder nesnesini oluşturduk. Builder nesnesinin hangi URL’den indirip parse edeceğini bilmesi için de bir URL nesnesi oluşturup URL’i verdik. Ardından belgenin belleğe alınma işlemini tamamlamak için bir Document nesnesi oluşturduk ve verdiğimiz URL ile openStream yaparak akışı tamamladık.
Belgeyi belleğe aldıktan sonra Currency etiketli alanları tek tek topluyoruz ve bunu bir NodeList nesnesine aktarıyoruz. Akabinde bir for döngüsü ile tüm Currency etiketli alanlar içindeki ebilgileri çekiyoruz. Ana etiketli (Kod, CurrencyCode) bilgileri çekerken Element nesnesi işimize yarıyor. Alt etiketli (Isim, CurrencyName vb.) bilgiler içinse getCharacterDataFromElement, getFloat, getElementValue metotları ile bilgileri çekiyoruz.
Diğer Java sınıfımızda ise kullandığımız nesneler ve get ve set metotları yer almakta. Xhtml sayfasında da dataTable kullandık. Ekran çıktısına ve merkez bankasının şu anki verilerine bakıp karşılaştırma yapalım. Resmi net görmek için üstüne tıklayın.
Bu yazıda da bu kadar arkadaşlar. Başka bir yazıda görüşmek üzere hoşçakalın.