Skip to content

Commit

Permalink
Use RelaxNG for validation instead of DTD for DocBook 5.2 (#170)
Browse files Browse the repository at this point in the history
* Add RelaxNG schema constants

* Check RelaxNG schema instead of DTD

* Add Jing JAR file and integrate into configure

* Delete DocBook 5.0RC4 related filed
  • Loading branch information
Girgias authored Oct 31, 2024
1 parent 4ebb4f2 commit 747c53b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 4,286 deletions.
45 changes: 25 additions & 20 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

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

const RNG_SCHEMA_DIR = __DIR__ . DIRECTORY_SEPARATOR . 'docbook' . DIRECTORY_SEPARATOR . 'docbook-v5.2-os' . DIRECTORY_SEPARATOR . 'rng' . DIRECTORY_SEPARATOR;
const RNG_SCHEMA_FILE = RNG_SCHEMA_DIR . 'docbook.rng';
const RNG_SCHEMA_XINCLUDE_FILE = RNG_SCHEMA_DIR . 'docbookxi.rng';

function usage() // {{{
{
global $acd;
Expand Down Expand Up @@ -800,7 +804,7 @@ function getFileModificationHistory(): array {
echo "Validating {$ac["INPUT_FILENAME"]}... ";
flush();
if ($ac['PARTIAL'] != '' && $ac['PARTIAL'] != 'no') { // {{{
$dom->validate(); // we don't care if the validation works or not
$dom->relaxNGValidate(RNG_SCHEMA_FILE); // we don't care if the validation works or not
$node = $dom->getElementById($ac['PARTIAL']);
if (!$node) {
echo "failed.\n";
Expand Down Expand Up @@ -838,7 +842,11 @@ function getFileModificationHistory(): array {
} // }}}

$mxml = $ac["OUTPUT_FILENAME"];
if ($dom->validate()) {

/* TODO: For some reason libxml does not validate the RelaxNG schema unless reloading the document in full */
$dom->save($mxml);
$dom->load($mxml, $LIBXML_OPTS);
if ($dom->relaxNGValidate(RNG_SCHEMA_FILE)) {
echo "done.\n";
printf("\nAll good. Saving %s... ", basename($ac["OUTPUT_FILENAME"]));
flush();
Expand Down Expand Up @@ -870,26 +878,23 @@ function getFileModificationHistory(): array {
exit(0); // Tell the shell that this script finished successfully.
} else {
echo "failed.\n";
echo "\nThe document didn't validate, ";

// Allow the .manual.xml file to be created, even if it is not valid.
if ($ac['FORCE_DOM_SAVE'] == 'yes') {
printf("writing %s anyway, and ", basename($ac["OUTPUT_FILENAME"]));
$dom->save($mxml);
}

if ($ac['DETAILED_ERRORMSG'] == 'yes') {
echo "trying to figure out what went wrong...\n";
echo "(This could take awhile. If you experience segfaults here, try again with --disable-xml-details)\n";
libxml_clear_errors(); // Clear the errors, they contain incorrect filename&line

$dom->load("{$ac['srcdir']}/{$ac["INPUT_FILENAME"]}", $LIBXML_OPTS | LIBXML_DTDVALID);
print_xml_errors();
echo "\nThe document didn't validate\n";

/**
* TODO: Integrate jing to explain schema violations as libxml is *useless*
* And this is not going to change for a while as the maintainer of libxml2 even acknowledges:
* > As it stands, libxml2's Relax NG validator doesn't seem suitable for production.
* cf. https://gitlab.gnome.org/GNOME/libxml2/-/issues/448
*/
$output = shell_exec('java -jar ' . $srcdir . '/docbook/jing.jar ' . RNG_SCHEMA_FILE. ' ' . $acd['OUTPUT_FILENAME']);
if ($output === null) {
echo "Command failed do you have Java installed?";
} else {
echo "here are the errors I got:\n";
echo "(If this isn't enough information, try again with --enable-xml-details)\n";
print_xml_errors(false);
echo $output;
}
//echo 'Please use Jing and the:' . PHP_EOL
// . '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
// . 'command to check why the RelaxNG schema failed.' . PHP_EOL;

// Exit normally when don't care about validation
if ($ac["FORCE_DOM_SAVE"] == "yes") {
Expand Down
8 changes: 0 additions & 8 deletions docbook/docbook-xml/README

This file was deleted.

4,246 changes: 0 additions & 4,246 deletions docbook/docbook-xml/docbook.dtd

This file was deleted.

Binary file added docbook/jing.jar
Binary file not shown.
5 changes: 2 additions & 3 deletions install-unix.xml.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN"
"./docbook/docbook-xml/docbook.dtd" [
<!DOCTYPE PHPDOC [

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

]>

<book xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="install" xml:lang="en" xmlns:xlink="http://www.w3.org/1999/xlink">
<book xmlns="http://docbook.org/ns/docbook" version="5.2" xml:id="install" xml:lang="en" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Installing PHP</title>
<preface>
<title>Preface</title>
Expand Down
5 changes: 2 additions & 3 deletions install-win.xml.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN"
"./docbook/docbook-xml/docbook.dtd" [
<!DOCTYPE PHPDOC [

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


<book id="install" lang="en">
<book xmlns="http://docbook.org/ns/docbook" version="5.2" xml:id="install" xml:lang="en">
<title>Installation on Windows systems</title>
<para>
Installing PHP on modern Microsoft Windows systems and recommended configuration with common web servers.
Expand Down
8 changes: 2 additions & 6 deletions manual.xml.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?xml version='1.0' encoding='@ENCODING@' ?>
<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN"
"./docbook/docbook-xml/docbook.dtd" [

<!-- $Revision$ -->

<!DOCTYPE PHPDOC [
<!-- Add translated specific definitions and snippets -->
@TRANSLATION_ONLY_INCL_BEGIN@
<!ENTITY % language-defs SYSTEM "../@LANGDIR@/language-defs.ent">
Expand Down Expand Up @@ -37,7 +33,7 @@
%frontpage.entities;
]>

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

Expand Down

0 comments on commit 747c53b

Please sign in to comment.