Last active
June 18, 2017 13:29
-
-
Save davidalves1/fa422760fa38c66231ef50bcafb80e49 to your computer and use it in GitHub Desktop.
Teste leitor XML
This file contains 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
<?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