1.4. My First DocBook File

First, you need a DocBook file to convert. Using your favorite text editor you can type (or cut and paste) the following lines:

Example 1.1. My first simple DocBook file

  1 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN">
    <article>
     
    <articleinfo>
  5 <title>XML rules the world!</title>
    </articleinfo>
     
    <section>
    <title>XML and DocBook do it together</title>
 10  
    <para>DocBook and XML are the golden twins 
    of the 21st certury !</para>
     
    </section>
 15 </article>
    

Then save it, say, with the name dbfile.xml.

This file has to be well-formed. To check an XML document, you can use the following tool:

$ rxp -s dbfile.xml

If you have catalog support the above source, in fact, can relate your XML source file to a Document Type Definition (DTD) for DocBook. A DTD defines the possible elements, their arguments, and their content models (which elements can contain which, how do elements relate to each other). If you have access to the relevant DTD, you can validate your file. At CERN, on Unix (with AFS) the DocBook DTD can also be referenced by adding the second line specifying its complete address, as follows:

<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
 "/afs/cern.ch/sw/XML/XMLBIN/share/www.oasis-open.org/docbook/xmldtd-4.2/docbookx.dtd"
 >

<article>
  .
  .
  .
</article>

To validate dbfile.xml, use the command:

$ rxp -s -V dbfile.xml

If errors are shown, read through the error log and correct errors from the beginning of the list first. Often, an early error has knock-on effects further down the processing of the document.

Alternatively, when using emacs there exists an XML processing mode, psgml, see Appendix AEmacs PSGML mode tips”.