8.120. DocBook-XML-4.5

The DocBook-4.5 XML DTD-4.5 package contains document type definitions for verification of XML data files against the DocBook rule set. These are useful for structuring books and software documentation to a standard allowing you to utilize transformations already written for that standard.

Approximate build time: 0.1 SBU
Required disk space: 1.2 MB

8.120.1. Installation of DocBook-4.5 XML DTD

Create the PKGBUILD for the docbook-xml package with the following commands:

mkdir /sources/docbook-xml
cd /sources/docbook-xml
cat > PKGBUILD << "REALEOF"
# Maintainer: Linux From Scratch <lfs-dev@lists.linuxfromscratch.org>

pkgname="docbook-xml"
pkgver="4.5"
pkgrel="1"
pkgdesc="The DocBook-4.5 XML DTD-4.5 package contains document type definitions for verification of XML data files against the DocBook rule set."
arch=('any')
url="http://www.docbook.org/"
license=('MIT')
groups=('core')
install=docbook-xml.install
depends=('libxml2')
makedepends=('bash'
             'coreutils'
             'libarchive'
             'unzip')
source=('http://www.docbook.org/xml/4.5/docbook-xml-4.5.zip')
md5sums=('03083e288e87a7e829e437358da7ef9e')

package(){
  # No need to change directory, it just unzips in ${srcdir}
  install -vdm755 "${pkgdir}/usr/share/xml/docbook/xml-dtd-4.5"
  install -vdm755 "${pkgdir}/etc/xml"
  cp -v -af --no-preserve=ownership docbook.cat *.dtd ent/ *.mod \
      "${pkgdir}/usr/share/xml/docbook/xml-dtd-4.5"

  # Create (or update) and populate the /etc/xml/docbook catalog
  xmlcatalog --noout --create "${pkgdir}/etc/xml/docbook"
  xmlcatalog --noout --add "public" \
      "-//OASIS//DTD DocBook XML V4.5//EN" \
      "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" \
      "${pkgdir}/etc/xml/docbook"
  xmlcatalog --noout --add "public" \
      "-//OASIS//DTD DocBook XML CALS Table Model V4.5//EN" \
      "file:///usr/share/xml/docbook/xml-dtd-4.5/calstblx.dtd" \
      "${pkgdir}/etc/xml/docbook"
xmlcatalog --noout --add "public" \
      "-//OASIS//DTD XML Exchange Table Model 19990315//EN" \
      "file:///usr/share/xml/docbook/xml-dtd-4.5/soextblx.dtd" \
      "${pkgdir}/etc/xml/docbook"
xmlcatalog --noout --add "public" \
      "-//OASIS//ELEMENTS DocBook XML Information Pool V4.5//EN" \
      "file:///usr/share/xml/docbook/xml-dtd-4.5/dbpoolx.mod" \
      "${pkgdir}/etc/xml/docbook"
xmlcatalog --noout --add "public" \
      "-//OASIS//ELEMENTS DocBook XML Document Hierarchy V4.5//EN" \
      "file:///usr/share/xml/docbook/xml-dtd-4.5/dbhierx.mod" \
      "${pkgdir}/etc/xml/docbook"
xmlcatalog --noout --add "public" \
      "-//OASIS//ELEMENTS DocBook XML HTML Tables V4.5//EN" \
      "file:///usr/share/xml/docbook/xml-dtd-4.5/htmltblx.mod" \
      "${pkgdir}/etc/xml/docbook"
xmlcatalog --noout --add "public" \
      "-//OASIS//ENTITIES DocBook XML Notations V4.5//EN" \
      "file:///usr/share/xml/docbook/xml-dtd-4.5/dbnotnx.mod" \
      "${pkgdir}/etc/xml/docbook"
xmlcatalog --noout --add "public" \
      "-//OASIS//ENTITIES DocBook XML Character Entities V4.5//EN" \
      "file:///usr/share/xml/docbook/xml-dtd-4.5/dbcentx.mod" \
      "${pkgdir}/etc/xml/docbook"
xmlcatalog --noout --add "public" \
      "-//OASIS//ENTITIES DocBook XML Additional General Entities V4.5//EN" \
      "file:///usr/share/xml/docbook/xml-dtd-4.5/dbgenent.mod" \
      "${pkgdir}/etc/xml/docbook"
xmlcatalog --noout --add "rewriteSystem" \
      "http://www.oasis-open.org/docbook/xml/4.5" \
      "file:///usr/share/xml/docbook/xml-dtd-4.5" \
      "${pkgdir}/etc/xml/docbook"
xmlcatalog --noout --add "rewriteURI" \
      "http://www.oasis-open.org/docbook/xml/4.5" \
      "file:///usr/share/xml/docbook/xml-dtd-4.5" \
      "${pkgdir}/etc/xml/docbook"

  # The above installation creates the files and updates the catalogs.
  # In order to utilize DocBook XML DTD V4.5 when any version 4.x is
  # requested in the System Identifier, you need to add additional
  # statements to the catalog files:
  for DTDVERSION in 4.1.2 4.2 4.3 4.4
  do
    xmlcatalog --noout --add "public" \
      "-//OASIS//DTD DocBook XML V$DTDVERSION//EN" \
      "http://www.oasis-open.org/docbook/xml/$DTDVERSION/docbookx.dtd" \
      "${pkgdir}/etc/xml/docbook"
    xmlcatalog --noout --add "rewriteSystem" \
      "http://www.oasis-open.org/docbook/xml/$DTDVERSION" \
      "file:///usr/share/xml/docbook/xml-dtd-4.5" \
      "${pkgdir}/etc/xml/docbook"
    xmlcatalog --noout --add "rewriteURI" \
      "http://www.oasis-open.org/docbook/xml/$DTDVERSION" \
      "file:///usr/share/xml/docbook/xml-dtd-4.5" \
      "${pkgdir}/etc/xml/docbook"
    xmlcatalog --noout --add "delegateSystem" \
      "http://www.oasis-open.org/docbook/xml/$DTDVERSION/" \
      "file:///etc/xml/docbook" \
      "${pkgdir}/etc/xml/catalog"
    xmlcatalog --noout --add "delegateURI" \
      "http://www.oasis-open.org/docbook/xml/$DTDVERSION/" \
      "file:///etc/xml/docbook" \
      "${pkgdir}/etc/xml/catalog"
  done
}
REALEOF

Create an install-script to handle removal, install, and upgrades:

cat > docbook-xml.install << "REALEOF"
# docbook-xml.install

post_install() {
  if [ -e etc/xml/catalog.preserve ]; then
    mv etc/xml/catalog.preserve etc/xml/catalog
  elif [ ! -e etc/xml/catalog ]; then
    xmlcatalog --noout --create etc/xml/catalog
  fi
  xmlcatalog --noout --add "delegatePublic" \
    "-//OASIS//ENTITIES DocBook XML" \
    "file:///etc/xml/docbook" \
    etc/xml/catalog
  xmlcatalog --noout --add "delegatePublic" \
    "-//OASIS//DTD DocBook XML" \
    "file:///etc/xml/docbook" \
    etc/xml/catalog
  xmlcatalog --noout --add "delegateSystem" \
    "http://www.oasis-open.org/docbook/" \
    "file:///etc/xml/docbook" \
    etc/xml/catalog
  xmlcatalog --noout --add "delegateURI" \
    "http://www.oasis-open.org/docbook/" \
    "file:///etc/xml/docbook" \
    etc/xml/catalog
}

# arg 1:  the new package version
# arg 2:  the old package version
pre_upgrade() {
  if [ $(vercmp $2 4.5) -lt 0 ]; then
    xmlcatalog --del "file:///etc/xml/docbook" etc/xml/catalog > etc/xml/catalog.preserve
  fi
}

post_upgrade() {
  if [ $(vercmp $2 4.5) -ge 0 ]; then
    post_remove
  fi
  post_install
}

post_remove() {
  xmlcatalog --noout --del file:///etc/xml/docbook etc/xml/catalog
}

REALEOF

Prepare the build directory for the pacman user and build the package:

chown -R root:pacman .
chmod 2775 .
chmod 664 PKGBUILD
su pacman -c 'makepkg -L --nodeps'

Add the newly created package to the central package repository:

cp docbook-xml-4.5-1-any.pkg.tar.xz \
   /srv/pacman/repos/LFS/
repo-add /srv/pacman/repos/LFS/LFS.db.tar.xz \
         /srv/pacman/repos/LFS/docbook-xml-4.5-1-any.pkg.tar.xz

Update the local cache and install the docbook-xml package:

pacman -Syu
pacman -S docbook-xml --overwrite \* -dd --noconfirm

Finally, copy the source files into the source repository and clean up the build directory:

mkdir /srv/pacman/source/LFS/docbook-xml
cp PKGBUILD /srv/pacman/source/LFS/docbook-xml
cd /sources
rm -rf docbook-xml

8.120.1.1. Config Files

/etc/xml/catalog and /etc/xml/docbook

In a packaged system, these files should be managed by the packager as per our PKGBUILD and docbook-xml.install files above.

8.120.2. Contents

Installed Files: DTD, MOD and ENT files
Installed Directories: /etc/xml and /usr/share/xml/docbook/xml-dtd-4.5

Short Descriptions

DTD files

contain a document type definition which defines the element types and the attribute lists that can be used in the corresponding XML files.

MOD files

contain components of the document type definition that are sourced into the DTD files.

ENT files

contain lists of named character entities allowed in HTML.