I decided to take my class and just turn it into some functions. It
works perfectly. I did not change any code except for removing the
class declaration and getting rid of the $this-> statements. I believe
that maybe my problem has to do with the use of xml_set_object() making
a reference to $this:
xml_set_object($this->Parser, &$this);
If this is the case, I'm not sure why it would show the correct results
in CData() but not at the end of GetArray(), but that's the only thing
I can think the problem may be.
Below is a copy of my code just as seperate functions. The code works
perfectly. I *really* wish I could find out why this won't work as a
class though...
<?
function GetArray($_FILE_)
{
global $Parser, $theArrayTopElement, $theArrayElements,
$theArrayPointer, $theArrayGetElement, $theArray;
$theArray = array();
$_FP_ = fopen($_FILE_, "r") or die("Cannot Open XML
Stream");
while ($_DATA_ = fread($_FP_, 4096))
{
if (!xml_parse($Parser, $_DATA_, feof($_FP_)))
{
return(FALSE);
}
}
fclose($_FP_);
return($theArray);
}
function Tag_Open($_PARSER_, $_TAG_, $_ATTR_)
{
global $Parser, $theArrayTopElement, $theArrayElements,
$theArrayPointer, $theArrayGetElement, $theArray;
$_ELEMENTS_ = explode("::", $theArrayElements);
for ($I = 0; $I < count($_ELEMENTS_); $I++)
{
if ($_TAG_ == $_ELEMENTS_[$I])
{
$theArrayGetElement = $_ELEMENTS_[$I];
}
}
}
function Tag_Close($_PARSER_, $_TAG_)
{
global $Parser, $theArrayTopElement, $theArrayElements,
$theArrayPointer, $theArrayGetElement, $theArray;
if ($_TAG_ == $theArrayTopElement)
{
$theArrayPointer++;
}
$theArrayGetElement = NULL;
}
function CData($_PARSER_, $_CDATA_)
{
global $Parser, $theArrayTopElement, $theArrayElements,
$theArrayPointer, $theArrayGetElement, $theArray;
if ($theArrayGetElement != NULL)
{
$theArray[$theArrayPointer]
[$theArrayGetElement] = $_CDATA_;
}
}
$theArrayTopElement = "ARTICLE";
$theArrayElements = "URL::TITLE";
$theArrayPointer = 0;
$theArrayGetElement = NULL;
$Parser = xml_parser_create("ISO-8859-1");
xml_set_element_handler($Parser, "Tag_Open", "Tag_Close");
xml_set_character_data_handler($Parser, "CData");
$NEWS = GetArray("myfile.xml");
print_r($NEWS);
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]