|
24 | 24 |
|
25 | 25 | echo "configure.php: $cvs_id\n";
|
26 | 26 |
|
| 27 | +const RNG_SCHEMA_DIR = __DIR__ . DIRECTORY_SEPARATOR . 'docbook' . DIRECTORY_SEPARATOR . 'docbook-v5.2-os' . DIRECTORY_SEPARATOR . 'rng' . DIRECTORY_SEPARATOR; |
| 28 | +const RNG_SCHEMA_FILE = RNG_SCHEMA_DIR . 'docbook.rng'; |
| 29 | +const RNG_SCHEMA_XINCLUDE_FILE = RNG_SCHEMA_DIR . 'docbookxi.rng'; |
| 30 | + |
27 | 31 | function usage() // {{{
|
28 | 32 | {
|
29 | 33 | global $acd;
|
@@ -800,7 +804,7 @@ function getFileModificationHistory(): array {
|
800 | 804 | echo "Validating {$ac["INPUT_FILENAME"]}... ";
|
801 | 805 | flush();
|
802 | 806 | if ($ac['PARTIAL'] != '' && $ac['PARTIAL'] != 'no') { // {{{
|
803 |
| - $dom->validate(); // we don't care if the validation works or not |
| 807 | + $dom->relaxNGValidate(RNG_SCHEMA_FILE); // we don't care if the validation works or not |
804 | 808 | $node = $dom->getElementById($ac['PARTIAL']);
|
805 | 809 | if (!$node) {
|
806 | 810 | echo "failed.\n";
|
@@ -838,7 +842,11 @@ function getFileModificationHistory(): array {
|
838 | 842 | } // }}}
|
839 | 843 |
|
840 | 844 | $mxml = $ac["OUTPUT_FILENAME"];
|
841 |
| -if ($dom->validate()) { |
| 845 | + |
| 846 | +/* TODO: For some reason libxml does not validate the RelaxNG schema unless reloading the document in full */ |
| 847 | +$dom->save($mxml); |
| 848 | +$dom->load($mxml, $LIBXML_OPTS); |
| 849 | +if ($dom->relaxNGValidate(RNG_SCHEMA_FILE)) { |
842 | 850 | echo "done.\n";
|
843 | 851 | printf("\nAll good. Saving %s... ", basename($ac["OUTPUT_FILENAME"]));
|
844 | 852 | flush();
|
@@ -870,26 +878,23 @@ function getFileModificationHistory(): array {
|
870 | 878 | exit(0); // Tell the shell that this script finished successfully.
|
871 | 879 | } else {
|
872 | 880 | echo "failed.\n";
|
873 |
| - echo "\nThe document didn't validate, "; |
874 |
| - |
875 |
| - // Allow the .manual.xml file to be created, even if it is not valid. |
876 |
| - if ($ac['FORCE_DOM_SAVE'] == 'yes') { |
877 |
| - printf("writing %s anyway, and ", basename($ac["OUTPUT_FILENAME"])); |
878 |
| - $dom->save($mxml); |
879 |
| - } |
880 |
| - |
881 |
| - if ($ac['DETAILED_ERRORMSG'] == 'yes') { |
882 |
| - echo "trying to figure out what went wrong...\n"; |
883 |
| - echo "(This could take awhile. If you experience segfaults here, try again with --disable-xml-details)\n"; |
884 |
| - libxml_clear_errors(); // Clear the errors, they contain incorrect filename&line |
885 |
| - |
886 |
| - $dom->load("{$ac['srcdir']}/{$ac["INPUT_FILENAME"]}", $LIBXML_OPTS | LIBXML_DTDVALID); |
887 |
| - print_xml_errors(); |
| 881 | + echo "\nThe document didn't validate\n"; |
| 882 | + |
| 883 | + /** |
| 884 | + * TODO: Integrate jing to explain schema violations as libxml is *useless* |
| 885 | + * And this is not going to change for a while as the maintainer of libxml2 even acknowledges: |
| 886 | + * > As it stands, libxml2's Relax NG validator doesn't seem suitable for production. |
| 887 | + * cf. https://gitlab.gnome.org/GNOME/libxml2/-/issues/448 |
| 888 | + */ |
| 889 | + $output = shell_exec('java -jar ' . $srcdir . '/docbook/jing.jar ' . RNG_SCHEMA_FILE. ' ' . $acd['OUTPUT_FILENAME']); |
| 890 | + if ($output === null) { |
| 891 | + echo "Command failed do you have Java installed?"; |
888 | 892 | } else {
|
889 |
| - echo "here are the errors I got:\n"; |
890 |
| - echo "(If this isn't enough information, try again with --enable-xml-details)\n"; |
891 |
| - print_xml_errors(false); |
| 893 | + echo $output; |
892 | 894 | }
|
| 895 | + //echo 'Please use Jing and the:' . PHP_EOL |
| 896 | + // . 'java -jar ./build/jing.jar /path/to/doc-base/docbook/docbook-v5.2-os/rng/docbookxi.rng /path/to/doc-base/.manual.xml' . PHP_EOL |
| 897 | + // . 'command to check why the RelaxNG schema failed.' . PHP_EOL; |
893 | 898 |
|
894 | 899 | // Exit normally when don't care about validation
|
895 | 900 | if ($ac["FORCE_DOM_SAVE"] == "yes") {
|
|
0 commit comments