Skip to content

Instantly share code, notes, and snippets.

@dannevang
Created June 15, 2015 13:33
Show Gist options
  • Save dannevang/cc8831d55c01717e2f72 to your computer and use it in GitHub Desktop.
Save dannevang/cc8831d55c01717e2f72 to your computer and use it in GitHub Desktop.
Get XML data from file
<?php
/* Demonstration on how to get product data from at XML file
* Mathias Dannevang <mathias@dannevang.org>
*/
//Function to call the XML file
function download_page($path){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$path);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$retValue = curl_exec($ch);
curl_close($ch);
return $retValue;
}
//Get the XML - INSERT URL TO XML FILE HERE
$url = download_page('http://server.com/product_list_en.xml');
//
$xml = new SimpleXMLElement($url);
//Loop through the data
foreach($xml->product as $product){
//do something with the data - here a simple echo
echo $product->id;
echo $product->mainCategory;
echo $product->subCategory;
echo $product->productFamily;
echo $product->catalogue;
echo $product->ageMin;
echo $product->ageMax;
echo $product->nbPlayers;
echo $product->size1;
echo $product->size2;
echo $product->size3;
echo $product->MVV;
echo $product->totalWeight;
echo $product->heaviestItem;
echo $product->InstallationTime;
echo $product->Concrete;
echo $product->Installers;
echo $product->imageThumb;
echo $product->imageFull;
echo $product->imagePhoto;
echo $product->image360;
echo $product->image360reel;
echo $product->video;
echo $product->imageSideView;
echo $product->productSheet;
echo $product->productMaterial;
echo $product->imageHD;
echo $product->product2dDFX;
echo $product->product2dDWG;
echo $product->product3dDWG;
echo '<br>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment