How to read XML in live standard? [closed]

2

I have a real estate system and I have developed my own XML standard for integration with Portals.

But the code that I use to read my XML, can not read the Viva Real standard.

Here is an example of the Viva Real pattern:

<ListingDataFeed xsi:schemaLocation="http://www.vivareal.com/schemas/1.0/VRSync">
<Header>
<PublishDate>2016-04-07T11:32:06</PublishDate>
<Provider>Agencia ArteDB</Provider>
<Email>[email protected]</Email>
<ContactName>Joaci Brito</ContactName>
<Telephone>(11) 982013467</Telephone>
<Logo>http://artedb.com.br/images/logo.png</Logo>
</Header>
<Listings>
<Listing>
<ListingID> 006</ListingID>
<Featured>true</Featured>
<ListDate>2016-01-21T01:51:08</ListDate>
<LastUpdateDate>2016-01-21T01:51:08</LastUpdateDate>
<TransactionType>For Sale</TransactionType>
<Title>Sobrado - Venda - Alvorada </Title>
<Location>
<Country abbreviation="BR">Brasil</Country>
<State abbreviation="SP">São Paulo</State>
<City>Guarulhos</City>
<Neighborhood>Alvorada </Neighborhood>
<PostalCode>07000-000</PostalCode>
<Zone>Zona Leste</Zone>
<Url>http://www.brunaalbuquerqueimoveis.com.br/detalharimovel.php?imovel=52d96ce4cba0c7.93798</Url>
<Latitude>-23.4444658</Latitude>
<Longitude>-46.4153649</Longitude>
</Location>
<Details>
<Description>Sobrado :: 3 Dorm. ( sendo um suite, mais dois dorm. um com sacada + banheiro para auxiliar os dormitórios solteiros), sala ( dois ambientes), lavabo, copa/cozinha, área de serv.no fundo coberta com amplo espaço no fundo para lazer + 2 vagas de garagem. Bairro com Toda Infraestrutura, proximo a escolas, farmácias, padaria e hospital, fácil acesso as avenidas principais e rodovia Presidente Dutra.  :: Obs.: Aceita Financiamento Pela Caixa Econômica ou qualquer outro banco de sua preferencia 
</Description>
<ListPrice currency="BRL">350000</ListPrice>
<PropertyAdministrationFee currency="BRL">0</PropertyAdministrationFee>
<PropertyType>Residential / Home</PropertyType>
<ConstructedArea unit="square metres">0</ConstructedArea>
<Bedrooms>3</Bedrooms>
<Bathrooms>2</Bathrooms>
<Suites>1</Suites>
<Garage type="Parking Space">2</Garage>
<LotArea unit="square metres">0</LotArea>
<Features/>
</Details>
<Media>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ab120776a80.01.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ab499d69c19.05.jpg</Item><Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ab5af593342.20.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ab71461d604.66.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ab8088f8392.44.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ab8e877d475.37.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ab976adf8f1.69.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ababd986a19.88.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535abb3c3b2420.52.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535abe736cb462.06.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ac10e808778.82.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ac28431e507.25.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ac3686a7c20.81.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ac46ee16e91.39.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535ac8b0944b01.72.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535acb37dae581.87.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535af0cf037f16.70.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535af2e7b68645.33.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535af56bc1aa27.12.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535af6b0bbc383.26.jpg</Item>
<Item medium="image">http://eclipse.artedb.com.br/arquivos/img2/IMO535af8354bb722.99.jpg</Item>
</Media>
<ContactInfo>
<Email>[email protected]</Email>
<Name>Imobiliária Nova União</Name>
<Telephone>2087-0293</Telephone>
<Website>brunaalbuquerqueimoveis.com.br</Website>
<Location>
<Country abbreviation="BR">Brasil</Country>
<State>SP</State>
</Location>
</ContactInfo>
<Status>
<PropertyStatus>Available</PropertyStatus>
<StatusDate>2016-01-21T01:51:08</StatusDate>
</Status>
</Listing>
</ListingDataFeed>

Now it follows the PHP code I use to read the XML that I developed within my default and that works perfectly, but does not capture the XML fields that are in the Viva Real pattern above:

$xml = file_get_contents('roteirodoimovel.xml');
// transformar o XML em um objeto
$sxml = new SimpleXMLElement($xml);
// iteracao por todo o XML:
foreach ($sxml as $linhaAtual) {
// obter cada item do xml referente ao campo da tabela
// cast porque a propriedade do objeto
// tambem é um objeto do tipo SimpleXMLElement

$id = (int) $linhaAtual->id;
$goal = (int) $linhaAtual->goal;
$idimv = (int) $linhaAtual->idimv; 
$url = (string) $linhaAtual->url; 
$urlimovel = (string) $linhaAtual->urlimovel; 
$agency_name = (string) $linhaAtual->agency_name; 
$agency_email = (string) $linhaAtual->agency_email; 
$logo = (string) $linhaAtual->logo; 
$type = (string) $linhaAtual->type; 
$property_type = (string) $linhaAtual->property_type; 
$title = (string) $linhaAtual->title; 
$content = (string) $linhaAtual->content; 
$rooms = (int) $linhaAtual->rooms; 
$bathrooms = (int) $linhaAtual->bathrooms; 
$parking = (int) $linhaAtual->parking; 
$floor_area = (string) $linhaAtual->floor_area; 
$price = (int) $linhaAtual->price; 
$region = (string) $linhaAtual->region; 
$city = (string) $linhaAtual->city; 
$country = (string) $linhaAtual->country; 
$neighborhood = (string) $linhaAtual->neighborhood; 
$address = (string) $linhaAtual->address; 
$picture_url = (string) $linhaAtual->picture_url;

What do I do to get him to read Viva Real's standards?

    
asked by anonymous 07.04.2016 / 14:19

1 answer

2

Just yesterday I was working on it. Try this fuction below. It will get the path to your xml, it will taravessar the nodes and will return an array in php. Dai is easy for you to manipulate. Note: Your xml must be valid, ie well-formatted, following the xml creation rules. Otherwise the simplexml_load_file and serialize function will not recognize the nodes.

    private function get_XML_Content($xml_Name_Path) {          
        $xml = simplexml_load_file($xml_Name_Path);
        $xml_arr_Content = unserialize(serialize(json_decode(json_encode((array) $xml), 1)));  
        return $xml_arr_Content;
    }




//Display sua array no browser:  
$arrXML = function get_XML_Content($o_camilho_ate_seu_XML);
echo "<pre>";
print_r($arrXML);
echo "</pre>";

And your xml default has an error in the <Listings> tag. If you remove it you will be able to read the file with the above function.

See the result of my test:

Array
(
    [@attributes] => Array
        (
            [schemaLocation] => http://www.vivareal.com/schemas/1.0/VRSync
        )

    [Header] => Array
        (
            [PublishDate] => 2016-04-07T11:32:06
            [Provider] => Agencia ArteDB
            [Email] => [email protected]
            [ContactName] => Joaci Brito
            [Telephone] => (11) 982013467
            [Logo] => http://artedb.com.br/images/logo.png
        )

    [Listing] => Array
        (
            [ListingID] =>  006
            [Featured] => true
            [ListDate] => 2016-01-21T01:51:08
            [LastUpdateDate] => 2016-01-21T01:51:08
            [TransactionType] => For Sale
            [Title] => Sobrado - Venda - Alvorada 
            [Location] => Array
                (
                    [Country] => Brasil
                    [State] => São Paulo
                    [City] => Guarulhos
                    [Neighborhood] => Alvorada 
                    [PostalCode] => 07000-000
                    [Zone] => Zona Leste
                    [Url] => http://www.brunaalbuquerqueimoveis.com.br/detalharimovel.php?imovel=52d96ce4cba0c7.93798
                    [Latitude] => -23.4444658
                    [Longitude] => -46.4153649
                )

            [Details] => Array
                (
                    [Description] => Sobrado :: 3 Dorm. ( sendo um suite, mais dois dorm. um com sacada + banheiro para auxiliar os dormitórios solteiros), sala ( dois ambientes), lavabo, copa/cozinha, área de serv.no fundo coberta com amplo espaço no fundo para lazer + 2 vagas de garagem. Bairro com Toda Infraestrutura, proximo a escolas, farmácias, padaria e hospital, fácil acesso as avenidas principais e rodovia Presidente Dutra.  :: Obs.: Aceita Financiamento Pela Caixa Econômica ou qualquer outro banco de sua preferencia 

                    [ListPrice] => 350000
                    [PropertyAdministrationFee] => 0
                    [PropertyType] => Residential / Home
                    [ConstructedArea] => 0
                    [Bedrooms] => 3
                    [Bathrooms] => 2
                    [Suites] => 1
                    [Garage] => 2
                    [LotArea] => 0
                    [Features] => Array
                        (
                        )

                )

            [Media] => Array
                (
                    [Item] => Array
                        (
                            [0] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ab120776a80.01.jpg
                            [1] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ab499d69c19.05.jpg
                            [2] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ab5af593342.20.jpg
                            [3] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ab71461d604.66.jpg
                            [4] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ab8088f8392.44.jpg
                            [5] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ab8e877d475.37.jpg
                            [6] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ab976adf8f1.69.jpg
                            [7] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ababd986a19.88.jpg
                            [8] => http://eclipse.artedb.com.br/arquivos/img2/IMO535abb3c3b2420.52.jpg
                            [9] => http://eclipse.artedb.com.br/arquivos/img2/IMO535abe736cb462.06.jpg
                            [10] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ac10e808778.82.jpg
                            [11] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ac28431e507.25.jpg
                            [12] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ac3686a7c20.81.jpg
                            [13] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ac46ee16e91.39.jpg
                            [14] => http://eclipse.artedb.com.br/arquivos/img2/IMO535ac8b0944b01.72.jpg
                            [15] => http://eclipse.artedb.com.br/arquivos/img2/IMO535acb37dae581.87.jpg
                            [16] => http://eclipse.artedb.com.br/arquivos/img2/IMO535af0cf037f16.70.jpg
                            [17] => http://eclipse.artedb.com.br/arquivos/img2/IMO535af2e7b68645.33.jpg
                            [18] => http://eclipse.artedb.com.br/arquivos/img2/IMO535af56bc1aa27.12.jpg
                            [19] => http://eclipse.artedb.com.br/arquivos/img2/IMO535af6b0bbc383.26.jpg
                            [20] => http://eclipse.artedb.com.br/arquivos/img2/IMO535af8354bb722.99.jpg
                        )

                )

            [ContactInfo] => Array
                (
                    [Email] => [email protected]
                    [Name] => Imobiliária Nova União
                    [Telephone] => 2087-0293
                    [Website] => brunaalbuquerqueimoveis.com.br
                    [Location] => Array
                        (
                            [Country] => Brasil
                            [State] => SP
                        )

                )

            [Status] => Array
                (
                    [PropertyStatus] => Available
                    [StatusDate] => 2016-01-21T01:51:08
                )

        )

)
    
07.04.2016 / 15:15