libxml catalogs on Windows

Anything
Awatar użytkownika
admin
Site Admin
Posty: 104
Rejestracja: ndz lip 17, 2011 8:51 am

libxml catalogs on Windows

Post autor: admin »

When using xsltproc and libxml, one needs to supply a set of document definitions, dtd and xsd files. They are downloadable from the net as archives. Usually each archive has a catalog file (actually 2 files, in 2 formats) that contains links to all the files from an archive. For example docbook-4.2. Sometimes there is no catalog file, then you link the main dtd directly.

I found it not straightforward to download a wanted archive of dtds. Sometimes it's easy to get a single dtd file, but it needs a dozen of other files with it, so an archive is the only reasonable solution. If you know a good place to get archives from, post it here.

Catalog files come in 2 formats:
  1. SGML catalog is a text file, usually named catalog without extension. Entries are like:

    Kod: Zaznacz cały

    PUBLIC "-//W3C//DTD XHTML 1.1//EN" "xhtml11.dtd"
  2. XML catalog is an xml file, starting from:

    Kod: Zaznacz cały

    <?xml version='1.0'?>
    <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
Now how to make libxml (xmllint or xsltproc) use these catalogs and dtds? Through XML_CATALOG_FILES environment variable. Although its plural, files, I couldn't force libxml to use more than one catalog file at a moment. So I produced a single catalog file that links to all other catalog files or straight to dtd files.

Here is my catalog.xml:

Kod: Zaznacz cały

<?xml version='1.0'?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
        
<public publicId="-//W3C//DTD XHTML 1.1//EN"
        uri="D:/Program_Files/xslt/dtds/xhtml11/xhtml11.dtd"/>

<nextCatalog catalog="d:/Program_Files/xslt/dtds/oasis-docbook-4.2/catalog.xml" />
<nextCatalog catalog="d:/Program_Files/xslt/dtds/docbook-xsl-ns-1.76.1/catalog.xml" />
<nextCatalog catalog="d:/Program_Files/xslt/dtds/docbook-xsl-1.77.1/catalog.xml" />
<nextCatalog catalog="d:/Program_Files/xslt/dtds/docbook-xsl-1.77.1/catalog.xml" />
</catalog>
A bat snippet for running xmllint with variables set:

Kod: Zaznacz cały

@echo off
set in=D:/some/dirs/dialog.xml
REM set XML_DEBUG_CATALOG=1
set XML_CATALOG_FILES=J:/lang/xml/catalog.xml
d:\program_files\xslt\bin\xmllint --noout --nonet --valid %in% --sax
If you have problems like xmllint unable to read the proper dtd file, you may set XML_DEBUG_CATALOG environment variable to 1 and get more info about catalog loading. That is usually sufficient. If a given entry seems to be not found by xmllint, just insert a public or system id into your custom catalog file.

You may also use SGML catalog, using --catalogs switch and SGML_CATALOG_FILES environment variable, but I found it sufficient to use the first format.

Thanks to catalog debugging I found that on my system a default location for catalog file is d:/Program_Files/xslt/etc/catalog. So I created that etc directory, copied my catalog.xml there and removed the extension. It works! Without specifying any vars.
ODPOWIEDZ