Created
May 10, 2021 16:17
-
-
Save brablc/2b01f2dce49152203a3b60125bf33857 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
if (!array_key_exists(1, $argv)) { | |
exit("Missing first param - path to parsed XML file! \nUse as {$argv[0]} </path/to/file.xml>\n"); | |
} | |
if (!file_exists($argv[1])) { | |
exit("File {$argv[1]} not found!\n"); | |
} | |
$checkedFile = $argv[1]; | |
libxml_use_internal_errors(TRUE); | |
$XML_PARSE_BIG_LINES = 4194304; // https://bugs.php.net/bug.php?id=54138 | |
$xml = new DOMDocument(); | |
$xml->load($checkedFile, LIBXML_PARSEHUGE | $XML_PARSE_BIG_LINES); | |
$xml->relaxNGValidate("products-complete-v10.rng"); | |
$errors = libxml_get_errors(); | |
if (empty($errors)) { | |
echo "PASSED\n"; | |
} else { | |
echo "Found some errors: \n==================\n\n"; | |
foreach ($errors as $error) { | |
printf("Line %06d\tcode %02d\t\t%s", $error->line, $error->code, $error->message); | |
} | |
printf("\n%d errors\n", count($errors)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: