blob: 6869b07bb6514d7533e2dd14ca918b3029beb3e4 [file] [log] [blame]
<?php
class QuotesParser {
public $quotesCatalog = array();
public $insideItem = false;
public $tag = "";
public $text = "";
public $image = "";
public $name = "";
public $position = "";
public $org = "";
public $link = "";
function add_quote(& $quote) {
$this->quotesCatalog[] = $quote;
}
function startElement($parser, $tagName, $attribs)
{
global $insideItem, $tag;
if ($insideItem) {
$tag = $tagName;
}
elseif ($tagName == "QUOTE")
{
$insideItem = TRUE;
}
}
function endElement($parser, $tagName)
{
global $quotesCatalog, $insideItem;
if ($tagName == "QUOTE")
{
$quotesTemp = array($this->text, $this->image, $this->name, $this->position, $this->org, $this->link);
$this->add_quote($quotesTemp);
$this->text = "";
$this->image = "";
$this->name = "";
$this->position = "";
$this->org = "";
$this->link = "";
$this->insideitem = FALSE;
}
}
function characterData($parser, $data)
{
global $insideItem, $tag;
if ($insideItem)
{
switch ($tag) {
case "TEXT":
$this->text .= $data;
break;
case "IMAGE":
$this->image .= $data;
break;
case "NAME":
$this->name .= $data;
break;
case "POSITION":
$this->position .= $data;
break;
case "ORG":
$this->org .= $data;
break;
case "LINK":
$this->link .= $data;
break;
}
}
}
}
$parser = xml_parser_create('');
$quotesParser = new QuotesParser();
xml_set_object($parser,$quotesParser);
xml_set_element_handler($parser, "startElement", "endElement");
xml_set_character_data_handler($parser, "characterData");
$documentRoot = $_SERVER['DOCUMENT_ROOT'];
$fp = fopen ($documentRoot. "/home/categories/scripts/quotes.xml", "r") or die ("File I/O Problem");
while ($data = fread($fp, 4096))
{
xml_parse($parser, $data, feof($fp)) or die("XML Error");
}
fclose ($fp);
xml_parser_free($parser);
?>