XML Dosyamızı hızlıca okur associative diziye çevirerek bize döndürür.
Sınıfımız;
Kullanımı (Uzak sunucudaki XML dosyayı okumak);
Local konumdaki XML Dosyayı okumak
iyi kullanımlar sorun oluşursa lütfen bildiriniz. 
Sınıfımız;
PHP:
<?php
class FastXML
{
public function __construct($xml_file, $file_mode=true)
{
if($file_mode)
{
$xml = self::_curl($xml_file);
$handle = fopen(md5($xml_file).'.xml', 'w+');
fwrite($handle, $xml);
fclose($handle);
$xmlf = new XMLReader;
$xmlf->open(md5($xml_file).'.xml');
$xml = self::_read($xmlf);
$xmlf->close();
return $xml;
}
else
{
$xmlf = new XMLReader;
$xmlf->open($xml_file);
$xml = self::_read($xmlf);
$xmlf->close();
return $xml;
}
}
private function _read()
{
$tree = null;
while($xml->read())
{
switch ($xml->nodeType)
{
case XMLReader::END_ELEMENT: return $tree;
case XMLReader::ELEMENT:
$node = array('tag' => $xml->name, 'value' => $xml->isEmptyElement ? '' : $this->fast_xml($xml));
if($xml->hasAttributes)
{
while($xml->moveToNextAttribute())
{
$node['attributes'][$xml->name] = $xml->value;
}
}
$tree[] = $node;
break;
case XMLReader::TEXT:
case XMLReader::CDATA:
$tree .= $xml->value;
break;
}
}
return $tree;
}
private function _curl($url)
{
$cURL = curl_init();
$header = array();
$header[0] = 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$header[1] = 'Cache-Control: max-age=0';
$header[2] = 'Connection: keep-alive';
$header[3] = 'Keep-Alive: 300';
$header[4] = 'Accept-Charset: ISO-8859-9,utf-8;q=0.7,*;q=0.7';
$header[5] = 'Accept-Language: en-us,en;q=0.5';
$header[6] = 'Pragma: ';
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
curl_setopt($cURL, CURLOPT_HTTPHEADER, $header);
curl_setopt($cURL, CURLOPT_HEADER, false);
curl_setopt($cURL, CURLOPT_REFERER, 'http://www.google.com.tr/');
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURL, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($cURL, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($cURL, CURLOPT_AUTOREFERER, true);
curl_setopt($cURL, CURLOPT_TIMEOUT, 30);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
$cURL_exec = curl_exec($cURL);
curl_close($cURL);
return $cURL_exec;
}
}
?>
PHP:
<?php
/*
*
* Sınıfı çalıştırdığımız gibi çağırdığımız değişkene xml'i okuyup aktarır.
*
*/
$xml = new FastXML('http://www.teknobeyin.com/sitemap.xml');
print_r($xml);
?>
PHP:
<?php
$xml = new FastXML('urladreslerim.xml', false);
print_r($xml);
?>