Skip to content

Instantly share code, notes, and snippets.

@davidalves1
Last active June 18, 2017 13:29
Show Gist options
  • Save davidalves1/fa422760fa38c66231ef50bcafb80e49 to your computer and use it in GitHub Desktop.
Save davidalves1/fa422760fa38c66231ef50bcafb80e49 to your computer and use it in GitHub Desktop.
Teste leitor XML
<?php
class LeitorXml
{
protected $path;
public function __construct($path)
{
$this->path = $path;
}
public function read()
{
$xml = simplexml_load_string($this->path) or die('Erro');
return $xml;
}
}
$url = 'http://url-do-arquivo.xml';
$file = file_get_contents($url);
$leitor_xml = new LeitorXml($file);
$xml = $leitor_xml->read();
if (!$xml)
exit('Não foi possível realizar a leitura do XML.')
$res = [
'name' => $xml->SimboCustomer->Name->__toString(),
'email' => $xml->SimboCustomer->Email->__toString(),
'site' => $xml->SimboCustomer->Site->__toString()
];
foreach ($xml->SimboRealtyList->SimboRealty as $item) {
$res['lista'][] = [
'type' => $item->Type->__toString(),
'subtype' => $item->SubType->__toString(),
'url' => $item->Url->__toString()
];
}
var_dump($res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment