<!DOCTYPE html>
<html>
<body>
<?php
$parser = xml_parser_create();
function char($parser, $data) {
echo $data;
}
function pi_handler($parser, $target, $data) {
echo "Target: $target<br>";
echo "Data: $data<br>";
}
xml_set_character_data_handler($parser, "char");
xml_set_processing_instruction_handler($parser, "pi_handler");
$fp = fopen("../demo/php/note_pi.xml", "r");
while ($data = fread($fp, 4096)) {
xml_parse($parser, $data, feof($fp)) or
die (sprintf("XML 错误:%s 在第 %d 行",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
xml_parser_free($parser);
?>
</body>
</html>