<?php $xml ='<?xml version="1.0" encoding="utf-8"?> <products> <product ID="12345"> <name>Sunny Beach Resort</name> <price currency="EUR">439.00</price> <URL>https://www.example.com/</URL> <images> <image>https://www.example.com/images/image.jpg</image> </images> <properties> <property name="country"> <value>Spanje</value> </property> <property name="region"> <value>Gran Canaria</value> </property> <property name="cityURL"> <value>https://www.example.com/</value> </property> <property name="serviceType"> <value>Logies ontbijt</value> </property> </properties> <variations> <variation> <property name="roomType"> <value>2-persoonskamer luxe type voor alleengebruik</value> </property> <property name="roomOccupation"> <value>geschikt voor 1 persoon</value> </property> </variation> <variation> <property name="roomType"> <value>2-persoonskamer luxe type standaard</value> </property> <property name="roomOccupation"> <value>geschikt voor 2 tot 3 personen</value> </property> </variation> </variations> </product></products>'; $xml = new simplexmlelement($xml); foreach($xml->product as $product) { foreach($product->properties->property as $property) { if($property['name'] == 'serviceType'){ echo 'Service type is' . $property->value . ' for ' . $product ->name; } } }
You have javascript disabled. You will not be able to edit any code.