8.3. Creating an XML DocBook document

For the ultimate reference guide see DocBook: The Definitive Guide. A template for a DocBook article is shown below:

[Note]Note

The output illustrated in this section was produced using a customisation of the stylesheets hence output on systems not implementing the same customisations may differ.

<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<article>
  <articleinfo>
    <title>Your title here</title>
        
    <author>
      <firstname>Your first name</firstname>
      <surname>Your surname</surname>
      <affiliation>
        <address><email>Your e-mail address</email></address>
      </affiliation>
    </author>
    
    <copyright>
      <year>2002</year>
      <holder role="mailto:your e-mail address">Your name</holder>
    </copyright>
  
    <abstract>
      <para>Include an abstract of the article's contents here.</para>
    </abstract>
  </articleinfo>

  <sect1><title>Section 1</title>
    <para>
      blah blah blah
    </para>
  </sect1>

  <sect1><title>Section 2</title>
    <para>
      blah blah blah
    </para>
  </sect1>  
</article>
      

DocBook books are generally for projects over 25 pages long, they allow the inclusion of chapters and parts, a book template is shown below:

<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<book>
  <bookinfo>
    <title>Your title here</title>
      
    <author>
      <firstname>Your first name</firstname>
      <surname>Your surname</surname>
      <affiliation>
        <address><email>Your e-mail address</email></address>
      </affiliation>
    </author>
   
    <copyright>
      <year>1998</year>
      <holder role="mailto:your e-mail address">Your name</holder>
    </copyright>
    
    <pubdate role="rcs">$Date: 2003/01/08 10:27:39 $</pubdate>
  
    <releaseinfo>$Id: DocBookSys-Chapter8-XML-Creating.xml,v 1.1.1.1 2003/01/08 10:27:39 ug55axm Exp $</releaseinfo>
  
    <abstract>
      <para>Include an abstract of the book&apos;s contents here.</para>
    </abstract>
  </bookinfo>
  
  <part><title>Part1</title>
    <chapter><title>Part 1, Chapter 1</title>
      <sect1><title>Part1, Chapter 1, Section1</title>
        <para>
	  Hello there!
	<para>
      </sect1> 
    </chapter>

    <chapter><title>Part 1, Chapter 2</title>
      <sect1><title>Part1, Chapter 2, Section 1</title>
        <para>
	  Hi there!
	<para>
      </sect1> 
    </chapter>
  </part>

  <part><title>Part2</title>
    <chapter><title>Part 2, Chapter 1</title>
      <sect1><title>Part 2, Chapter 1, Section1</title>
        <para>
	  GoodDay there!
	<para>
      </sect1> 

      <sect1><title>Part2, Chapter1, Section2</title>
        <para>
	  GoodNight there! 
	<para>
      </sect1> 
    </chapter>
  </part>
</book>
      

This can be validated using xmllint like this:

xmllint --valid --nooutarticletemplatewin.xml

This should produce no errors and exit silently because the document is structured correctly. Chunked XHTML output can be generated like this:

xsltproc file:///path/to/docbook-xsl/xhtml/chunk.dsl articletemplate.xml

There is a DocBook element quick reference card available from http://www.dpawson.co.uk/docbook/reference.html#d3e60.