XML Parser in PHP does not work

0

I am trying to implement an XML parse code in PHP, I believe I configured it following the right logic, but it is not working. It works if I use it with an RSS feed, however the RSS Feed does not have the links of the images. The final goal is to remove the following values:

<nome>
<descricao>
<link_produto>
<link_imagem>
<preco_promocao>
<preco_normal>
<parcelas>
<vl_parcelas>

You are returning a blank page, in the error log it returns the following:

[27-May-2017 04:18:20 UTC] PHP Warning:  Invalid argument supplied for foreach() in /home/SITE/public_html/va/artigos-complexos/afilio/afilio-vitrinexml.php on line 12

The function:

simplexml_load_file

works perfectly because

allow_url_fopen

is enabled in the server's php.

The code is as follows:

<link rel="stylesheet" href="/va/artigos-complexos/afilio/afilio-vitrine.css" type="text/css" />

<div class="mainproductebayfloatright-bottom">

<?php
/* XML PARSER*/

$feedurl = "http://v2.afilio.com.br/aff/aff_get_boutique.php?boutiqueid=37930-895687&token=53e355b0a09ea0.74300807&progid=1199&format=XML";

$rss = simplexml_load_file($feedurl);

foreach ($rss->boutique->produto as $item) {
    $link = $item->link_do_produto;
    $title = $item->nome;
    $description = $item->descricao;

    ?>

        <div class="aroundebay">
        <div id="aroundebay2">


<?php
        print "<div class=\"titleebay\"><a href=\"$link\">" . $title . "</a></div>";
        print $description;
    ?>
        </div>
        </div>

</div>
<?php  }

CSS Code:

.mainproductebayfloat-bottom {
    display: block;
}
#aroundebay {
    margin-right: auto;
    margin-left: auto;
    display: table;
}
#aroundebay2 {
    border: 1px #48719D;
    border-style: solid;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    color: #48719D;
    margin-left: 5px;
    float: left;
    margin-bottom: 10px;
    background-color: #FFFFFF;
}
@media only screen and (min-width: 1px) {
    #aroundebay2 {
        height: 300px;
        width: 95%;
    }
}
@media only screen and (min-width: 320px) {
    #aroundebay2 {
        height: 220px;
        width: 95%;
    }
}
@media only screen and (min-width: 480px) {
    #aroundebay2 {
        height: 250px;
        width: 95%;
    }
}
@media only screen and (min-width: 640px) {
    #aroundebay2 {
        height: 220px;
        width: 48%;
    }
}
@media only screen and (min-width: 720px) {
    #aroundebay2 {
        height: 215px;
        width: 48%;
    }
}
@media only screen and (min-width: 960px) {
    #aroundebay2 {
        height: 250px;
        width: 30%;
    }
}
#aroundebay2 a {
    font-weight: bolder;
}
.titleebay {
    background: #48719D;
    padding: 2px 5px 5px 5px;
    border-radius: 5px 5px 1px 1px;
    -moz-border-radius: 5px 5px 1px 1px;
    -webkit-border-radius: 5px 5px 1px 1px;
}
.titleebay a {
    color: #fff;
    text-shadow: #000 1px 1px 1px;
    height: 38px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.titleebay a:hover {
    color: #CCCCCC;
}
    
asked by anonymous 27.05.2017 / 06:23

1 answer

0

The error is in this line:

foreach ($rss->boutique->produto as $item) {

pq $ rss- > boutique- > product is null What happens is that boutique is the root element, so it's already loaded in $ rss variable, you can skip the call to it, try doing so:

foreach ($rss->produto as $item) {
    
27.05.2017 / 06:55