...

View Full Version : xml_set_external_entity_ref_handler() handler never called



gsnedders
04-01-2007, 01:40 AM
Under the following code, basic_parser::entity_ref() is never called, despite there being a PUBLIC/SYSTEM entity.

<?php

class basic_parser
{
function parse($data, $encoding)
{
$this->xml = xml_parser_create_ns($encoding);
xml_set_object($this->xml, $this);
xml_set_external_entity_ref_handler($this->xml, 'entity_ref');
var_dump(xml_parse($this->xml, $data, true), xml_get_error_code($this->xml), xml_error_string(xml_get_error_code($this->xml)), xml_get_current_line_number($this->xml), xml_get_current_column_number($this->xml));
}

function entity_ref($parser, $open_entity_names, $base, $system_id, $public_id)
{
var_dump($parser, $open_entity_names, $base, $system_id, $public_id);
}
}

$parser = new basic_parser;

$data = '<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE rdf:RDF [
<!ENTITY % HTMLlat1 PUBLIC
"-//W3C//ENTITIES Latin 1 for XHTML//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">
%HTMLlat1;
]>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
>
<channel>
<title>This&nbsp;That</title>
</channel>
</rdf:RDF>';

$parser->parse($data, 'ISO-8859-1');

?>

xml_parse() also manages to return 0, giving the script the following output:

int(0)
int(26)
string(23) "Undeclared entity error"
int(7)
int(3)

Line 7 column 3 is the LF after the end of the DOCTYPE.

gsnedders
04-10-2007, 03:11 AM
Anyone at all?

gsnedders
05-18-2007, 08:46 PM
Well, having gone over this with a friend in IRC (slowly trying loads of possibilities), we've concluded that xml_set_external_entity_ref_handler()'s handler isn't called on either PHP 4.4.7 or PHP 5.2.2, that the DOCTYPE is never seen in PHP under PHP 5.2.2, and is partially within xml_set_default_handler()'s handler on PHP 4.4.7.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum