blob: 8ea3e99ed0efa9f770f43092cf27f995d2ac1ca6 [file] [log] [blame]
<?php
class ReviewsParser {
var $reviewsCatalog = array();
var $insideItem = false;
var $tag = "";
var $title = "";
var $link = "";
var $date = "";
var $author = "";
var $language = "";
var $shortDesc = "";
function add_review(& $review) {
$this->reviewsCatalog[] = $review;
}
function startElement($parser, $tagName, $attribs)
{
global $insideItem, $tag;
if ($insideItem) {
$tag = $tagName;
}
elseif ($tagName = "REVIEW")
{
$insideItem = TRUE;
}
}
function endElement($parser, $tagName)
{
global $reviewsCatalog, $insideItem;
if ($tagName == "REVIEW")
{
$reviewsTemp = array($this->title, $this->link, $this->author, $this->date, $this->language, $this->shortDesc);
$this->add_review($reviewsTemp);
$this->title = "";
$this->link = "";
$this->author = "";
$this->date ="";
$this->language="";
$this->shortDesc="";
$this->insideitem = FALSE;
}
}
function characterData($parser, $data)
{
global $insideItem, $tag;
if ($insideItem)
{
switch ($tag) {
case "TITLE":
$this->title .= $data;
break;
case "LINK":
$this->link .= $data;
break;
case "AUTHOR":
$this->author .= $data;
break;
case "DATE":
$this->date .= $data;
break;
case "LANGUAGE":
$this->language .= $data;
break;
case "SHORTDESC":
$this->shortDesc .= $data;
break;
}
}
}
}
$parser = xml_parser_create('');
$reviewsParser = new ReviewsParser();
xml_set_object($parser,&$reviewsParser);
xml_set_element_handler($parser, "startElement", "endElement");
xml_set_character_data_handler($parser, "characterData");
$fp = fopen ("reviews.xml", "r") or die ("File I/O Problem");
//stream_filter_append($fp, 'convert.base64-encode');
while ($data = fread($fp, 4096))
{
xml_parse($parser, $data, feof($fp)) or die("XML Error");
}
fclose ($fp);
xml_parser_free($parser);
?>