XML Parse Syntax Error
| From: | Tom Culpepper | Date: | Fri, 13 Dec 2002 23:06:02 +0000 |
| Subject: | XML Parse Syntax Error | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-128220@lists.php.net to get a copy of this message | ||
I am working on an XML parser and trying to learn about them. All the scripts I get from the net in various tutorials and such all return nothing but "XML error: syntax error at line 1". I checked the variables with PHPINFO() and it says that XML support is on. I also know that keeping the PHP up to date is not a priority around here as we are still on PHP3. Any thoughts on what this might be? Is the server jsut showing it's need for an update again?
-tom
here is one example of the code I am using:
$xml_file = "data.xml";
echo "<table border=0 cellpadding=5>";
echo "<tr><th colspan=2>XML Articles</th></tr>";
function startElement($parser_instance, $element_name, $attrs) {
switch($element_name) {
case "URL" : echo "<tr><td><a href=\"";
break;
case "SUMMARY" : echo "<td>";
break;
}
}
function characterData($parser_instance, $xml_data) {
echo $xml_data;} function endElement($parser_instance, $element_name) {
switch($element_name) {
case "URL" : echo "\">";
break;
case "TITLE" : echo "</a></td>";
break;
case "SUMMARY" : echo "</td></tr>";
break;
}
}
$parser = xml_parser_create();
xml_set_element_handler($parser, "startElement", "endElement");
xml_set_character_data_handler($parser, "characterData");
if (!($filehandler = fopen($xml_file, "r"))) {
die("could not open XML input");
}
while ($data = fread($filehandler, 4096)) {
if (!xml_parse($parser, $data, feof($filehandler))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
}
fclose($filehandler);
xml_parser_free($parser);
echo "</table>";