<?xml version="1.0" encoding="UTF-8"?>
<essay xml:lang="en" version="5.0" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:gal="http://norman.walsh.name/rdf/gallery#" xmlns:foaf="http://xmlns.com/foaf/0.1/">
<info>
    
    
    
    
    
    
    
    
    
    
    
    
<title>notAllowed?</title><biblioid class="uri">http://norman.walsh.name/2006/10/27/notAllowed</biblioid>
<volumenum>9</volumenum>
<issuenum>105</issuenum>
<pubdate>2006-10-27T12:00:22-04:00</pubdate>
<date>$Date: 2006-10-27 13:03:35 -0400 (Fri, 27 Oct 2006) $</date>
<author>
      <personname>
<firstname>Norman</firstname>
	<surname>Walsh</surname>
</personname>
    </author>
<copyright>
      <year>2006</year>
      <holder>Norman Walsh</holder>
    </copyright>
<abstract>
<para>On customizing DocBook and the importance of sometimes being
optionally not allowed.</para>
</abstract>
<dc:subject rdf:resource="http://norman.walsh.name/knows/taxonomy#DocBook"/>
<dc:subject rdf:resource="http://norman.walsh.name/knows/taxonomy#RELAXNG"/>
</info>

<para xml:id="p1">Huge numbers of people use
<wikipedia>DocBook</wikipedia> straight out of the box, without ever
customizing it or changing anything. That's hardly surprising; if
you're writing technical documentation, chances are good DocBook
covers everything you need. Even if there are a couple of places where
some small changes would make it fit your particular needs even
better, the cost of designing the schema customization, augmenting the
processing tools, and training your authors, who probably already know
stock DocBook, is often not worth the effort.</para>

<para xml:id="p2">But suppose it is, suppose you do want to make some changes. One
thing you can do that's essentially free is remove optional stuff. As
long as you do that, you're making a subset and you don't have to
change anything except the schema (your authoring tool is presumably
driven off the schema, hopefully the
<wikipedia page="RELAX_NG">RELAX NG</wikipedia> one, and the stylesheets
and processing tools don't have to be changed
<link xlink:href="http://www.docbook.org/tdg5/en/html/ch05.html">for a subset</link>).
</para>

<para xml:id="p3">Subsetting makes the schema smaller and often simplifies
authoring <wikipedia page="User_interface">UIs</wikipedia>. This is
particularly true of attributes because they're often presented in
some sort of drop-down list. The first set of attributes to fall under
the knife when I'm doing this sort of thing are the effectivity
attributes. The writing I do doesn't tend to need the
profiling that they support, and removing them knocks 10 attributes off
every element in one fell swoop.</para>

<para xml:id="p4">In a DocBook V5.0 customization layer, it's easy to remove things,
just make them <literal>notAllowed</literal>:</para>

<programlisting>db.effectivity.attributes = notAllowed</programlisting>

<para xml:id="p5">Except, after you do this, validation produces some odd messages,
like this one:</para>

<programlisting>$ msv db.rng test.xml 
start parsing a grammar.
validating test.xml
Error at line:1, column:48 of file:///home/ndw/scratch/test.xml
  element "article" was found where no element may occur

the document is NOT valid.</programlisting>

<para xml:id="p6">Of course, the first time you encounter this, it's likely to be in a
customization layer that does a bit more than lop off the effectivity attributes
so it can take a while to figure out what's wrong.</para>

<para xml:id="p7">But the effectivity attributes are what's wrong. Can you see why?
Maybe this will help:</para>

<programlisting>db.common.attributes =
   db.xml.id.attribute?
 &amp; db.version.attribute?
 &amp; db.xml.lang.attribute?
 &amp; db.xml.base.attribute?
 &amp; db.remap.attribute?
 &amp; db.xreflabel.attribute?
 &amp; db.revisionflag.attribute?
 &amp; db.dir.attribute?
 &amp; db.effectivity.attributes</programlisting>

<para xml:id="p8">See it now?</para>

<para xml:id="p9">The problem is that the effectivity attributes are a
<emphasis>required</emphasis> part of the common attributes (common attributes
are ones that appear on every DocBook element). So when you make the
effectivity attributes “<literal>notAllowed</literal>”, you've created an
unsatisfiable pattern: every element must include something which is not allowed.
</para>

<para xml:id="p10">The consequence is that no element pattern in the schema can possibly
match any DocBook element. To fix this, make the effectivity attributes
<emphasis>optionally</emphasis> not allowed<footnote>
      <para xml:id="p11">You may have noticed
that this could also be fixed by making the <literal>db.effectivity.attributes</literal>
pattern optional in the common attributes. But if you did that, it
would be much harder to create a customization layer that required one
of the effectivity attributes. Not that I see a lot of point in doing that,
as it happens.</para>
    </footnote>:</para>

<programlisting>db.effectivity.attributes = notAllowed?</programlisting>

<para xml:id="p12">There:</para>

<programlisting>$ msv db.rng test.xml 
start parsing a grammar.
warnings are found. use -warning switch to see all warnings.
validating test.xml
the document is valid.</programlisting>

<para xml:id="p13">That's better. (Thanks to <personname>
      <firstname>Scott</firstname>
<surname>Hudson</surname>
    </personname> for providing the real-life example
that actually brought this to my attention.)</para>

</essay>

