Pascale,
Je poursuis dans nos aventures, voici un script très simple en PHP pour lire la structure d'un fichier XML : read-index3.php.
<?php $file = "index.xml"; $depth = array(); print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"; print " \"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd\">\n"; print "<html>\n"; print "<head><title>Essai de lecture avec PHP</title></head>\n"; print "<body>\n"; print "<h1>lecture de la structure avec le script read-index3.php</h1>\n"; print "<p>Voir l'article de"; print " <a href=\"/weblog/archives/000065.html#000065\">"; print "Normandie WebLog</a></p>\n<pre>"; function startElement($parser, $name, $attrs) { global $depth; for ($i = 0; $i < $depth[$parser]; $i++) { print " "; } print "$name\n"; $depth[$parser]++; } function endElement($parser, $name) { global $depth; $depth[$parser]--; } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); print "</pre></body></html>"; ?>Posted by karl at juillet 03, 2002 07:34 PM