[Fontconfig] DTD

Peter Flynn peter at silmaril.ie
Sun Apr 1 14:01:15 UTC 2018

On 30/03/18 23:04, Lawrence D'Oliveiro wrote:
> On Fri, 30 Mar 2018 18:41:34 +0000, Jerry Casiano wrote:
>> I would consider [the lack of a DTD] a bug if I used Debian.
> Does anybody still use DTDs for anything? 

Yes, extensively. See discussions ad perpetuam in the markup field (eg 
Balisage :-)

> They may have made sense with SGML, but HTML, for example, does so
> much more with CSS instead.
CSS isn't connected in any way with using a DTD. A DTD is like a Schema: 
it provides a machine-readable framework for an editor to use to ensure 
that only valid element types are used, and only in valid places. CSS is 
used for styling output (eg HTML), and does not affect document 
construction in any way.

> And as for XML, it seems to me a DTD is neither necessary nor
> sufficient to capture the semantics of most real-world applications.
It depends what your real-world applications are.

If you are using XML to represent rectangular data (eg a config file, 
spreadsheet, or database table) then a W3C Schema with its datatypes is 
probably more useful. This is known as "data"-XML.

In the publishing industry, however, where they deal with continuous 
text, not rectangular data, DTDs are terser and simpler and better 
supported by the toolchain (and data types are not useful or meaningful 
for continuous text). This is known as "document"-XML.

In either case, hardly anyone nowadays actually codes a DTD or Schema by 
hand; most are machine-generated from a better and more comprehensive 
language like Relax-NG or ODD.

> Fontconfig being a case in point: half of fonts.dtd is comments
> explaining what the constructs actually mean. 

DTDs have no comment declaration syntax of their own, so using XML 
comment declarations is the only solution. But comments are good: 
uncommented code is usually regarded as A Bad Thing.

> And much of the rest is
> essentially content-free syntax like
>      <!ELEMENT dir (#PCDATA)>

This reflects the relatively light weight of markup needed to describe 
the application data. It's basically a set of containers, so all it 
needs is the names: the content is just strings. I must admit I would 
have written it differently, but that's just a matter of coding style :-)

I did find a much older version that was even simpler...

> And things like
>      <!ELEMENT plus (%expr;)*>

I was surprised when I saw this. It appears that someone decided to try 
and store code that could be extracted and executed in some way. Not 
that there's anything technically wrong with it; just a little unusual.

> convey that these operators are recognized and can take multiple
> operands, but nothing more.

That's exactly it. A DTD is just a spec. Its principal use is to 
guarantee that the files which claim to conform to it really do 
(validation). The utilities to do this are easily available, eg onsgmls 
(part of OpenSP) or rxp (from the LTxml2 toolkit at Edinburgh University).


More information about the Fontconfig mailing list