#!/usr/bin/php | +----------------------------------------------------------------------+ $Id$ */ if (!isset($_SERVER["argv"][1])) { echo "Purpose: Check XML syntax of single PHP manual file.\n"; echo "Usage: xml-check.php filename.xml [xmllint-command]\n"; echo "Note: Links are not checked.\n"; exit(); } $file = file_get_contents($_SERVER["argv"][1]); $xmllint = (isset($_SERVER["argv"][2]) ? $_SERVER["argv"][2] : "xmllint"); $root = str_replace('\\', '/', dirname(__FILE__)); $root = substr($root, 0, strrpos($root, '/')); $realpath = str_replace('\\', '/', realpath($_SERVER["argv"][1])); $example_filename = "$root/xml-check.xml"; $rootpos = strlen($root) + 1; $language = substr($realpath, $rootpos, strpos($realpath, '/', $rootpos) - $rootpos); $header = preg_replace('~.*(]*>)(.*)~s', "\\1$header" . (!preg_match("~Example\\2\n" : "\\2") . "\n\n", $file); $fp = fopen($example_filename, "wb"); fwrite($fp, $file); fclose($fp); passthru("XMLLINT_INDENT=' ' $xmllint --noent --noout --encode UTF-8 --format --valid $example_filename 2> $example_filename.out"); // xmllint outputs to stderr which is not catched by shell_exec, 2> &1 doesn't work on Windows $errors = file_get_contents("$example_filename.out"); $errors = preg_replace("~.*validity error : IDREF attribute linkend references an unknown ID.*\n.*\n.*\n~", "", $errors); $errors = str_replace($example_filename, $_SERVER["argv"][1], $errors); if (empty($errors)) { echo "Success: Your file passed this XML check, do consider running 'make test' as well.\n"; } else { echo "Errors: The following XML error exist:\n"; echo $errors; } //~ unlink("$example_filename"); unlink("$example_filename.out"); ?>