Skip to content

Commit 747c53b

Browse files
authored
Use RelaxNG for validation instead of DTD for DocBook 5.2 (#170)
* Add RelaxNG schema constants * Check RelaxNG schema instead of DTD * Add Jing JAR file and integrate into configure * Delete DocBook 5.0RC4 related filed
1 parent 4ebb4f2 commit 747c53b

File tree

7 files changed

+31
-4286
lines changed

7 files changed

+31
-4286
lines changed

configure.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
echo "configure.php: $cvs_id\n";
2626

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+
2731
function usage() // {{{
2832
{
2933
global $acd;
@@ -800,7 +804,7 @@ function getFileModificationHistory(): array {
800804
echo "Validating {$ac["INPUT_FILENAME"]}... ";
801805
flush();
802806
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
804808
$node = $dom->getElementById($ac['PARTIAL']);
805809
if (!$node) {
806810
echo "failed.\n";
@@ -838,7 +842,11 @@ function getFileModificationHistory(): array {
838842
} // }}}
839843

840844
$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)) {
842850
echo "done.\n";
843851
printf("\nAll good. Saving %s... ", basename($ac["OUTPUT_FILENAME"]));
844852
flush();
@@ -870,26 +878,23 @@ function getFileModificationHistory(): array {
870878
exit(0); // Tell the shell that this script finished successfully.
871879
} else {
872880
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?";
888892
} 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;
892894
}
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;
893898

894899
// Exit normally when don't care about validation
895900
if ($ac["FORCE_DOM_SAVE"] == "yes") {

docbook/docbook-xml/README

Lines changed: 0 additions & 8 deletions
This file was deleted.

docbook/docbook-xml/docbook.dtd

Lines changed: 0 additions & 4246 deletions
This file was deleted.

docbook/jing.jar

753 KB
Binary file not shown.

install-unix.xml.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version='1.0' encoding='UTF-8' ?>
2-
<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN"
3-
"./docbook/docbook-xml/docbook.dtd" [
2+
<!DOCTYPE PHPDOC [
43

54
<!ENTITY % language-defs SYSTEM "../@LANGDIR@/language-defs.ent">
65
<!ENTITY % language-snippets SYSTEM "../@LANGDIR@/language-snippets.ent">
@@ -21,7 +20,7 @@
2120

2221
]>
2322

24-
<book xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="install" xml:lang="en" xmlns:xlink="http://www.w3.org/1999/xlink">
23+
<book xmlns="http://docbook.org/ns/docbook" version="5.2" xml:id="install" xml:lang="en" xmlns:xlink="http://www.w3.org/1999/xlink">
2524
<title>Installing PHP</title>
2625
<preface>
2726
<title>Preface</title>

install-win.xml.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version='1.0' encoding='UTF-8' ?>
2-
<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN"
3-
"./docbook/docbook-xml/docbook.dtd" [
2+
<!DOCTYPE PHPDOC [
43

54
<!ENTITY % language-defs SYSTEM "../@LANGDIR@/language-defs.ent">
65
<!ENTITY % language-snippets SYSTEM "../@LANGDIR@/language-snippets.ent">
@@ -26,7 +25,7 @@
2625
en/install/windows/index.xml file to build this file -->
2726

2827

29-
<book id="install" lang="en">
28+
<book xmlns="http://docbook.org/ns/docbook" version="5.2" xml:id="install" xml:lang="en">
3029
<title>Installation on Windows systems</title>
3130
<para>
3231
Installing PHP on modern Microsoft Windows systems and recommended configuration with common web servers.

manual.xml.in

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<?xml version='1.0' encoding='@ENCODING@' ?>
2-
<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN"
3-
"./docbook/docbook-xml/docbook.dtd" [
4-
5-
<!-- $Revision$ -->
6-
2+
<!DOCTYPE PHPDOC [
73
<!-- Add translated specific definitions and snippets -->
84
@TRANSLATION_ONLY_INCL_BEGIN@
95
<!ENTITY % language-defs SYSTEM "../@LANGDIR@/language-defs.ent">
@@ -37,7 +33,7 @@
3733
%frontpage.entities;
3834
]>
3935

40-
<set xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="index" xml:lang="@LANG@" xmlns:xlink="http://www.w3.org/1999/xlink">
36+
<set xmlns="http://docbook.org/ns/docbook" version="5.2" xml:id="index" xml:lang="@LANG@" xmlns:xlink="http://www.w3.org/1999/xlink">
4137
<title>&PHPManual;</title>
4238
&bookinfo;
4339

0 commit comments

Comments
 (0)