In adding an xml product feed to my site, I would also like to include the images.
This is how the xml shows the image:
<images>
<image>
<size>
<![CDATA[ large ]]>
</size>
<tag>
<![CDATA[ default ]]>
</tag>
<type>
<![CDATA[ Default image for the product ]]>
</type>
<location>
<![CDATA[ https://www.website.com/image.jpeg ]]>
</location>
</image>
</images>
This is the code I have so far:
<?php
$xml_data = simplexml_load_file("https://website.com/file.xml")
or die("Error: Object Creation failure");
foreach ($xml_data->children() as $data)
{
if (str_contains($data->category, 'shampoo')) {
echo "<div class='col-md-4'>";
echo "<div class='item-xml'>";
echo "<div class='title-xml'>$data->title</div>";
echo "<div class='image-xml'><img src='$data->images'></div>";
echo "<div class='price-xml'>€ $data->price</div>";
echo "<a href='$data->link' target='_blank'><div class='link-xml'></div></a>";
echo "</div>";
echo "</div>";
}
}
?>
I tried changing this line
echo "<div class='image-xml'><img src='$data->images'></div>";
into this
echo "<div class='image-xml'><img src='(array_values($data->images[0]->location))'></div>";
and this (“.” instead of “->”)
echo "<div class='image-xml'><img src='(array_values($data->images[0].location))'></div>";
But none works.
How can I get to the path of the image url, please?