blob: 185c821ea4cfabf7738eabc5b0fbe7f8f560bb2e [file] [log] [blame]
<?php
class QuotesParser {
var $quotesCatalog = array();
var $insideItem = false;
var $tag = "";
var $text = "";
var $image = "";
var $name = "";
var $position = "";
var $org = "";
var $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");
$fp = fopen ("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);
?>