Welcome to the Kelkoo Group Customer Service

Parsing XML – PHP

Here is an example showing how to parse the product Search result in xml in PHP

  • CSS code example: productsResult.css
  • productSearchV3Result.xml example: productSearchV3Result.xml
  • PHP code parse xml example
  • Download Example
  • if (file_exists('/tmp/productSearchV3Result.xml')) {
        $productsResult = simplexml_load_file('/tmp/productSearchV3Result.xml');
        $products = $productsResult -> Products;;
    
        print "<div id='allProduct'>";
        foreach ($products[0] as $OneProduct) {
    
            $OneOffer = $OneProduct -> Offer;
    
            $title = $OneOffer -> Title ;
            $images = $OneOffer -> Images;
            $image  = $images[0] -> Image -> Url;
            $leadUrl = $OneOffer -> Url;
            $priceElem = $OneOffer -> Price;
            $price = $priceElem -> Price;
    
    
           print " <div class='oneProduct' > ";
           print "   <div class='img'>  <a href='$leadUrl' >  <img src='$image' /> </a>  </div> ";
           print "    <div class='title'>  $title  </div> ";
           print "    <div class='price'>  $price € </div> ";
           print "</div>";
    
        print "</div>";
        }
    
    } else {
        exit('/tmp/productSearchV3Result.xml  does not exist ');
    }
    
    

    parseXml