Arbre XML d'un fichier project STAF-18 (EVA) déposée

Ce formulaire s'addresse aux gens qui veulent programmer PHP/XML ou aux curieux qui veulent regarder la structure de leur fichier XML. $content\n"; } echo "
"; } } function stack_printer ($el) { echo "$el "; } function show_stack ($indent) { global $stack, $astack; global $pointer, $apointer, $current; global $xml_tree, $xml_stack, $xml_data, $xml_attrs, $html_tree echo "$indent\n"; array_walk ($stack, 'stack_printer'); // echo "Current attrs : "; // array_walk ($astack[$apointer], 'stack_printer'); // echo "
\n"; } // ----------------------- The 3 functions for the PHP XML Parser // xml_parse fait appel à ces fonctions // grab current element and push it onto the stack // push its attributs on the astack function startElement($parser, $name, $attrs) { global $stack, $astack; global $pointer, $apointer, $current; global $xml_tree, $xml_stack, $xml_data, $xml_attrs, $html_tree; $pointer = push ($stack, $name) -1 ; $apointer = push ($astack, $attrs) -1 ; // the current element $current = $name; if ($html_tree) { echo "\n
  • $current
      \n"; }; if ($xml_tree) { echo "\n
    1. <$current>
        \n"; }; if ($xml_stack) { show_stack("\nstack=\n"); }; if ($xml_attrs) { attr_printer($attrs); } ; } // pop off the element from the stack // pop off the attributes from the astack function endElement($parser, $name) { global $stack, $astack; global $pointer, $apointer, $current; global $xml_tree, $xml_stack, $xml_data, $xml_attrs, $html_tree; if ($html_tree) {echo "\n
    2. \n"; }; if ($xml_tree) { echo "\n
    </" . $stack[$pointer] . ">
  • \n"; }; if ($xml_stack) { show_stack("\n
    stack=\n"); }; pop ($stack); pop ($astack); $pointer = $pointer - 1; $apointer = $apointer - 1; $current = FALSE; } function characterData($parser, $data) { global $stack, $astack; global $pointer, $apointer, $current; global $xml_tree, $xml_stack, $xml_data, $xml_attrs, $html_tree; if ($xml_stack) { show_stack("
    DATA current=" . $current . " stack="); }; if ($xml_data) { if (trim($data) != "") { if (!$xml_tree) { echo "
    "; } ; echo "\"$data\"\n"; } } } // -------------------- XML Parser function parse_xml($file) { // create the XML Parser, a new one for each filep $xml_parser = xml_parser_create("ISO-8859-1"); 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"); // echo "

    DEBUG: file = $file"; if (!($fp = fopen($file, "r"))) { die( "could not open XML input"); } else { // init per-file global vars $wp_count = 0; } while ($data = fread($fp, 50000)) { 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))); } } // close file and free parser fclose($fp); xml_parser_free($xml_parser); } // ------------------------------ File ops function make_file_option($file) { echo "

    \n"; echo ""; } // ---------------------------------------------------------------------- // ----------------------- Main routine // -------------------------- Get the list of files $handle=opendir($project_dir); // read the files into an array $files = array(); while ($file = readdir($handle)) { $pieces = explode(".", $file); if ($pieces[1] == "xml") { $files[] = $file; } } closedir($handle); // sort them in alphabetical order sort($files); reset($files); // ------------------------------ Make a HTML form ?>

    >
    XML TREE HTML TREE No tree
    XML Stack TREE (long) Data (element contents) Attributes

    Restart Over ] "; echo "[ Source Code ]
    "; // ------------------------------ Here we deal with form requests if ($projectfile) // to call like ?projectfile=file.xml { // ----- PARSE XML // --- fix options if ($display == "xml_tree") { $xml_tree = "on";} elseif ($display == "html_tree") { $html_tree = "on";} // XML stack needs xml_tree //if ($xml_stack) $xml_tree = "on"; // An URL to contents $xml_url = $xml_path . $projectfile; $url = $xml_servlet . "?xml=" . $xml_url . "&xsl=" . $style_sheet; echo "

    Tree display for $projectfile: \n"; // ----- DOIT // calls xml_parse for the file, which in turn calls // - startElement when it finds an open tag // - endElement when it finds a close tag // - characterData when it finds CDATA (things inside a tag including blanks) echo "

    "; } ?>
    Gestion de projets | Retour à STAF-18
    D.K.S.