Ceci est un test de Xtract pour la gestion des projets Staf-18. Pour Xtract, il existe un petit
tutoriel.
Notez que vous pouvez bookmarker les queries effectués (on utilise un GET).
Note: Pour le moment, il n'existe pas de XML Query Language "officiel".
Xtract fait penser à XSLT et il est basé sur la proposition
"XQL". Voir aussi
la SQL FAQ..
Le débat est ouvert ....
Voir par exemple XML_QL
qui est très différent de Xtract.
// TODO
// - parametrize the url of this file
// - combined canned queries with form widgets
// - Do basic queries rather with XSLT
// ------------------------------ GLOBALS AND INITS --------------
$project_dir = "/web/staf/staf-e/staf18/proj/";
$xtract = "/local/bin/Xtract";
// rip off \ and add quotes to the query string ... pff quellemerdeatrouver
$fixed_query = "\"" . stripslashes(rawurldecode($query)) . "\"";
$cmd_1 = $xtract . " " . $fixed_query . " ";
// xml + xsl programs and files
$xml_servlet = "http://tecfa2.unige.ch:8080/servlet/XSLatorServlet";
$style_sheet = "http://tecfa.unige.ch/staf/staf-e/staf18/project.xsl";
// ----- XML translation tables
// this is too bloody minimal, but before I get into this, I'd like
// to do a generic project.dtd PHP formatter.
$begin_array = array(
"query-output" => " ",
"teacher-comment" => "
Teacher Comment
",
"title" => "",
"list" => "
",
"item" => "
",
"content" => "
",
"para" => "
"
);
$end_array = array(
"teacher-comment" => "
",
"title" => "
",
"content" => "",
"list" => "",
"item" => ""
);
function startElement($parser, $name, $attrs) {
global $begin_array;
if ($htmlexpr = $begin_array[$name]) {
print "$htmlexpr";
}
else {
print "
$name:";
}
if ($name != "list") {
// --- print attributes
while (list ($attr, $content) = each ($attrs)){
echo "$attr = $content\n";
}
echo "
";
}
}
function endElement($parser, $name) {
global $end_array;
if ($htmlexpr = $end_array[$name]) {
print "$htmlexpr";
}
else {
// un paragraphe pour etre sur
print "
";
}
}
function characterData($parser, $data)
{
// echo "
\n";
echo "$data \n";
// echo "
\n";
}
// process a file
function process_file ($file) {
global $project_dir;
global $cmd_1;
global $xml_servlet;
global $style_sheet;
$file_path = $project_dir . $file;
$cmd = $cmd_1 . $file_path;
// echo "
\n" ;
// init XML Parser
$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");
exec ($cmd, $xtract_output, $status);
// We have to wrap each xtract_output into some xml tag, else the parser
// will freak out.
xml_parse($xml_parser, "", 0);
// input xtract_output to xml_parser
while ( list ($junk, $data) = each ($xtract_output) ) {
// echo "\n
DEBUG: data = $data
\n";
// echo "\nDEBUG: feof(fp) = " . feof($fp);
if (!xml_parse($xml_parser, $data, 0)) {
die(sprintf( "XML error: %s at line %d, column %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser),
xml_get_current_column_number($xml_parser)
));
}
}
// tell the parser that we are done
xml_parse($xml_parser, "", 1);
// free parser
xml_parser_free($xml_parser);
}
// -------------------- table of contents
function print_toc_el ($file) {
echo "