If you'd have registered I could have sticky mailed you the names of a couple of great guys who could sort this type of issue in their sleep - contact me via my profile site if u think this may help u.
Should really be posting this question in the webmasters corner, but no one seems to post there.
I am working on a website http://www.what2get4them.co.uk
I intend to use AW datafeeds.
I don't want to use the shopwindow software as I don't feel I have you have enough freedom to play with it, and I am not experienced enough to write my own software.
My programming experience extends to php, and mysql. XML just seems to blow me away, and I don't have a lot of time to read a thick slab of pages to get to grips with it.
So what I intend to do is transfer the xml feeds directly into mysql database and use that.
Now here is my problem:
I have found a simple xml parser in php on the net, I have modified it work with an AW XML feed, and then added my own php to end of the script to put each product into mysql database.
I have got this part working fine, however. I have to download the feed first, upload it to my server then the run application. The reason is because the xml feeds are generated from php script at the AW end, so if tell give my parser the URL for the feed it will not read it as an xml file. I have tried using several php functions but can't get them to work, such as file_get_contents. Does anyone know of a way, using php, where I can load the contents of the whole file to a php variable for use, or download the xml file and save it to my server without user intervention.
My script is as follows:
<?php
//The database connection file
include('dbconnect.php');
// the xml file we want to parse
$xmlSource="test.xml";
//First we define a number of variables to store the data from each element
$Advertiser = "";
$language = "";
$masterCategoryID = "";
$masterCategory = "";
$offerID = "";
$productID = "";
$productname = "";
$brand = "";
$promotionText = "";
$description = "";
$deepLink = "";
$imageURL = "";
$delivery = "";
$validFrom = "";
$validUntil = "";
$Price = "";
//holds the name of the current element
$currentElement="";
//array to hold all the product data
$theproduct=array();
/* The start Element Handler
* This is where we store the element name, currently being parsed, in $currentElement.
*/
function startElement($parser,$name)
{
$GLOBALS['currentElement']=$name;
}
//end startElement()
/*
* The end Element Handler
*/
function endElement($parser,$name){
$elements=array('Advertiser','language','masterCat egoryID','masterCategory','offerID'
,'productID','productname','brand','promotionText' ,'description','deepLink','imageURL'
,'delivery','validFrom','validUntil','Price');
if(strcmp($name,"Price")==0){
foreach($elements as $element){
$temp[$element]=$GLOBALS[$element];
}
$GLOBALS['theproduct'][]=$temp;
$GLOBALS['Advertiser']="";
$GLOBALS['language']="";
$GLOBALS['masterCategoryID']="";
$GLOBALS['masterCategory']="";
$GLOBALS['offerID']="";
$GLOBALS['productID']="";
$GLOBALS['productname']="";
$GLOBALS['brand']="";
$GLOBALS['promotionText']="";
$GLOBALS['description']="";
$GLOBALS['deepLink']="";
$GLOBALS['imageURL']="";
$GLOBALS['delivery']="";
$GLOBALS['validFrom']="";
$GLOBALS['validUntil']="";
$GLOBALS['Price']="";
}
}//end endElement()
/* The character data Handler
* Depending on what the currentElement is,
* the handler assigns the value to the appropriate variable
*/
function characterData($parser, $data) {
$elements = array ('Advertiser','language','masterCategoryID','maste rCategory','offerID'
,'productID','productname','brand','promotionText' ,'description','deepLink','imageURL'
,'delivery','validFrom','validUntil','Price');
foreach ($elements as $element) {
if ($GLOBALS["currentElement"] == $element) {
$GLOBALS[$element] .= $data;
}
}
}
/* This is where the actual parsing is going on.
* parseFile() parses the xml document and return an array
* with the data we asked for.
*/
function parseFile(){
global $xmlSource,$theproduct;
/*Creating the xml parser*/
$xml_parser=xml_parser_create();
/*Register the handlers*/
xml_set_element_handler($xml_parser,"startElement" ,"endElement");
xml_set_character_data_handler($xml_parser,"charac terData");
/*Disables case-folding. Needed for this example*/
xml_parser_set_option($xml_parser,XML_OPTION_CASE_ FOLDING,false);
/*Open the xml file and feed it to the parser in 4k blocks*/
if(!($fp=fopen($xmlSource,"r"))){
die("Cannot open $xmlSource ");
}
while(($data=fread($fp,4096))){
if(!xml_parse($xml_parser,$data,feof($fp))){
die(sprintf("XML error at line %d column %d ",
xml_get_current_line_number($xml_parser),
xml_get_current_column_number($xml_parser)));
}
}
/*Finish ! we free the parser and returns the array*/
xml_parser_free($xml_parser);
return $theproduct;
}//end parseFile()
/************************************************** *************************************************
Calling the parseFile() and getting the result into a mysql database
************************************************** *************************************************/
$result=parseFile();
$productcount = 1;
foreach($result as $arr){
/*check on offerID to see if we reached a new product.
*/
if(strcmp($id,$arr["offerID"])!=0){
$Merchant = $arr["Advertiser"];
$Language = $arr["language"];
$CategoryID = $arr["masterCategoryID"];
$Category = $arr["masterCategory"];
$OfferID = "" . $Merchant{0} . $Merchant{1} . $arr["offerID"] . $Merchant{strlen($Merchant)-2} . $Merchant{strlen($Merchant)-1} . "";
$ProductID = $OfferID;
$ProdName = $arr["productname"];
$Brand = $arr["brand"];
$Promo = $arr["promotionText"];
$Description = $arr["description"];
$Link = $arr["deepLink"];
$Image = $arr["imageURL"];
$Delivery = $arr["delivery"];
$VFrom = $arr["validFrom"];
$VUntil = $arr["validUntil"];
$Cost = str_replace("GBP","",$arr["Price"]);
$Cost = str_replace(" ","",$Cost);
$insertquery="INSERT INTO ProductTable (ProductID,Merchant,Language,CategoryID,Category,O fferID,ProdName,Brand,Promo,Description,Link,Image ,Delivery,VFrom,VUntil,Cost) VALUES
('$ProductID','$Merchant','$Language','$CategoryID ','$Category','$OfferID','$ProdName','$Brand','$Pr omo','$Description','$Link','$Image','$Delivery',' $VFrom','$VUntil','$Cost')";
$check = mysql_query($insertquery);
if($check == 1){echo"$productcount - $OfferID - $ProdName $Cost Inserted";
$productcount = $productcount + 1;}
else{echo"$OfferID - $ProdName $Cost NOT INSERTED";}
}
$id=$arr["offerID"];
}
?>
If you'd have registered I could have sticky mailed you the names of a couple of great guys who could sort this type of issue in their sleep - contact me via my profile site if u think this may help u.
Make some real money:
Affiliates : www.affiliate-marketing-school.com
Merchants : www.lead-clearing-house.com
Connect with me on LinkedIn http://www.linkedin.com/in/mrmichaelanthony
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks