X-Git-Url: https://git.cweiske.de/phorkie.git/blobdiff_plain/09b7728bd2beca1270922a38d79498e3c4fa0456..d9f6b83ed6d8a4546e4119c64b639adda057d25e:/src/phorkie/Tool/Xmllint.php diff --git a/src/phorkie/Tool/Xmllint.php b/src/phorkie/Tool/Xmllint.php new file mode 100644 index 0000000..b9917f5 --- /dev/null +++ b/src/phorkie/Tool/Xmllint.php @@ -0,0 +1,44 @@ +getPath(); + $fpathlen = strlen($fpath); + + $res = new Tool_Result(); + $cmd = 'xmllint --noout ' . escapeshellarg($fpath) . ' 2>&1'; + exec($cmd, $output, $retval); + if ($retval == 0) { + $res->annotations['general'][] = new Tool_Result_Line( + 'XML is well-formed', 'ok' + ); + return $res; + } + + for ($i = 0; $i < count($output); $i += 3) { + $line = $output[$i]; + if (substr($line, 0, $fpathlen) != $fpath) { + throw new Exception('xmllint does not behave as expected: ' . $line); + } + list($line, $msg) = explode(':', substr($line, $fpathlen + 1), 2); + $res->annotations[$line][] = new Tool_Result_Line( + $msg, 'error' + ); + } + + $res->annotations['general'][] = new Tool_Result_Line( + 'XML is not well-formed', 'error' + ); + + return $res; + } +} + +?> \ No newline at end of file