PHP + XML

From: Date: Mon, 17 Feb 2003 14:39:40 +0000
Subject: PHP + XML
Groups: php.general 
Request: Send a blank email to php-general+get-135831@lists.php.net to get a copy of this message
Hi, I have a problem with PHP and XML, I can't get the right data out of the XML file. I made a small example of what I want: --- Code --- function startElement($xml_parser, $name, $attrs) { echo "[$name]<br>";} function externalEntityRefHandler($xml_parser, $openEntityNames, $base, $systemId,$publicId) {
    echo "External ?";
} function endElement($xml_parser, $name) { echo "[/$name]<br>";} function characterData($xml_parser, $text) {
    echo "Handling characterdata: '".$text."'<br>";
} $xml_parser = xml_parser_create(); xml_parser_set_option( $xml_parser, XML_OPTION_CASE_FOLDING, false ); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); xml_set_external_entity_ref_handler($xml_parser, "externalEntityRefHandler"); // Parse the XML data. // open XML file if (!($fp = fopen("test.xml", "r"))) {
     die("Cannot locate XML data file");
} // read and parse data while ($data = fread($fp, 4096)) {
    echo "<br>".$data."<hr>";
    if (!xml_parse($xml_parser, $data, feof($fp))) {
     echo "XML error in given {$data} on line ".
          xml_get_current_line_number($xml_parser) .
         '  column ' . xml_get_current_column_number($xml_parser) .
         '. Reason: ' .
         xml_error_string(xml_get_error_code($xml_parser));
    }
} --- End Code --- --- text.xml --- <?xml version="1.0" standalone="no"?> <!DOCTYPE DOCUMENT [ <!ENTITY % ISOlat1 PUBLIC "-//W3C//ENTITIES Latin 1 for XHTML//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent"> %ISOlat1; ]> <DOCUMENT> <TITLE>Das Hildebrandslied, circa 775 C.E. </TITLE> <LINE>Ik gih&ocirc;rta dhat seggen,</LINE> <LINE>dhat sih urh&ecirc;ttun &aelig;non muot&icirc;n,</LINE> <LINE>Hiltibrant enti Hadhubrant untar heriun tu&ecirc;m. </LINE> <LINE>sunufatarungo: iro saro rihtun,</LINE> <COMMENT>I'll spare you the next 61 lines</COMMENT> </DOCUMENT> --- End test.xml --- The output I get is : %ISOlat1; ]> Ik gihôrta dhat seggen, dhat sih urhêttun ænon muotîn, Hiltibrant enti Hadhubrant untar heriun tuêm. sunufatarungo: iro saro rihtun, I'll spare you the next 61 lines [DOCUMENT] Handling characterdata: ' ' Handling characterdata: ' ' [TITLE] Handling characterdata: 'Das Hildebrandslied, circa 775 C.E. ' [/TITLE] Handling characterdata: ' ' Handling characterdata: ' ' [LINE] Handling characterdata: 'Ik gih' Handling characterdata: 'rta dhat seggen,' [/LINE] Handling characterdata: ' ' Handling characterdata: ' ' [LINE] Handling characterdata: 'dhat sih urh' Handling characterdata: 'ttun ' Handling characterdata: 'non muot' Handling characterdata: 'n,' [/LINE] Handling characterdata: ' ' Handling characterdata: ' ' [LINE] Handling characterdata: 'Hiltibrant enti Hadhubrant untar heriun tu' Handling characterdata: 'm. ' Handling characterdata: ' ' Handling characterdata: ' ' [/LINE] Handling characterdata: ' ' Handling characterdata: ' ' Handling characterdata: ' ' [LINE] Handling characterdata: 'sunufatarungo: iro saro rihtun,' [/LINE] Handling characterdata: ' ' Handling characterdata: ' ' [COMMENT] Handling characterdata: 'I'll spare you the next 61 lines' [/COMMENT] Handling characterdata: ' ' [/DOCUMENT] As you can see, all the HTML entities are dissapeard ??? What am I doing wrong ? Regards, Sandy

« previous php.general (#135831) next »