Skip to content

Instantly share code, notes, and snippets.

@brablc
Created May 10, 2021 16:17
Show Gist options
  • Save brablc/2b01f2dce49152203a3b60125bf33857 to your computer and use it in GitHub Desktop.
Save brablc/2b01f2dce49152203a3b60125bf33857 to your computer and use it in GitHub Desktop.
#!/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));
}
@brablc
Copy link
Author

brablc commented May 10, 2021

Usage:

wget https://www.shoptet.cz/export/schema/products-{datatype,supplier,complete}-v10.rng https://gist.githubusercontent.com/brablc/2b01f2dce49152203a3b60125bf33857/raw/87a507b647451cdc6abb2913464c0772f0a94096/st-xml-validate-complete
chmod u+x st-xml-validate-complete
xmllint --format IMPORT.xml > IMPORT_formatted.xml
./st-xml-validate-complete IMPORT_formatted.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment