I'm using these functions to parse an RSS site:
<?php
$currentElements = array();
$newsArray = array();
// Reads XML file into formatted html
function readXML($xmlFile)
{
$xmlParser = xml_parser_create();
xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($xmlParser, startElement, endElement);
xml_set_character_data_handler($xmlParser, characterData);
$fp = fopen($xmlFile, "r");
while($data = fread($fp, 4092)) {
//$data = htmlentities($data, ENT_QUOTES);
xml_parse($xmlParser, $data, feof($fp));
}
xml_parser_free($xmlParser);
}
// Sets the current XML element, and pushes itself onto the element hierarchy
function startElement($parser, $name, $attrs)
{
global $currentElements, $itemCount;
array_push($currentElements, $name);
if($name == "item"){$itemCount += 1;}
}
// Prints XML data; finds highlights and links
function characterData($parser, $data)
{
global $currentElements, $newsArray, $itemCount;
$currentCount = count($currentElements);
$parentElement = $currentElements[$currentCount-2];
$thisElement = $currentElements[$currentCount-1];
if($parentElement == "item"){
$newsArray[$itemCount-1][$thisElement] = htmlentities($data, ENT_QUOTES);}
else{
switch($name){
case "title":
break;
case "link":
break;
case "description":
break;
case "language":
break;
case "item":
break;}}
}
// If the XML element has ended, it is poped off the hierarchy
function endElement($parser, $name)
{
global $currentElements;
$currentCount = count($currentElements);
if($currentElements[$currentCount-1] == $name){
array_pop($currentElements);}
}
?>
But when I parse the following site:
http://news.com.com/2547-1_3-0-20.xml
I get major problems... large portions of text are just missing (usually between single quote marks) and the "link" field is always missing everything but the last variable in a GET string.
Help!!