I'm working on a script that will only include the designated elements and their character data of a xml file, as seen in the $listArr array on line 51, however, right now, the unwanted elements are still making their way through to the output. If anyone can tell me what is wrong with the script, I'd really appreciate it. I've reached the point of being officially stuck.

First, the XML (test.xml):
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<hork>this is HORK</hork>
<hork>this is HORK</hork>
<hork>this is HORK</hork>
<hork>this is HORK</hork>
<hork>this is HORK</hork>
<hork>this is HORK</hork>
<hork>this is HORK</hork>
<hork>this is HORK</hork>
<tacos>this is tacos</tacos>
<target>no print</target>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
<to>Tove</to>
<target>no print</target>
<target>no print</target>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
<whatever>yes</whatever>
</note>
And this is the xml parsing script:
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Title</title>
<style type="text/css">
    #parsewrap {margin:0px auto; border: solid red 2px; width:500px; text-align:center;}
</style>
</head>
<body>
<div id="parsewrap">
<?php

$parser
=xml_parser_create();

function 
start($parser,$element_name,$element_attrs)
  {
  switch(
strtolower($element_name))
    {
    case 
"note":
    echo 
"\t<div style=\"color:red;background-color:yellow;\">\n\t\tRED TEXT";
    break;
    case 
"to":
    echo 
"\n\t</div>\n\t<div style=\"color:green;\">\n\t\tTo: ";
    break; 
    case 
"from":
    echo 
"\n\t</div>\n\t<div style=\"color:blue;\">\n\t\tFrom: ";
    break; 
    case 
"heading":
    echo 
"\n\t</div>\n\t<div style=\"color:purple;\">\n\t\tHeading: ";
    break; 
    case 
"body":
    echo 
"\n\t</div>\n\t<div style=\"color:orange; background-color:black;\">\n\t\tMessage: ";
    }
  }

function 
stop($parser,$element_name)
  {
  echo 
"";
  }

function 
char($parser,$content)
  {
  echo 
trim($content);
  }

xml_set_element_handler($parser,"start","stop");

xml_set_character_data_handler($parser,"char");

$fp=fopen("test.xml","r"); 
$listArr = array("to""from""heading""body"); //these wouuld be the elements that I DO want extracted out of the massive XML data
$wanted each($listArr);
 
while (
$data=fread($fp,4096)) {
    
    while (
eregi($wanted$data)) {
        list(
$before$after) = spliti("<".$wanted.">"$data2);
        list(
$value$newafter) = spliti("</".$wanted.">"$after2);
        
$data $newafter;
        
$piece "<".$wanted.">".$value."</".$wanted.">";
        
$content $content $piece;
    }
  
xml_parse($parser,$data,feof($fp)) or 
  die (
sprintf("XML Error: %s at line %d"
  
xml_error_string(xml_get_error_code($parser)),
  
xml_get_current_line_number($parser)));
  }

xml_parser_free($parser);
?>

    </div>
</div>
</body>
</html>