4. Sections

The top level tag in our slowly growing document is <article>. Because this is the top level tag it will "contain" all other tags. In other words, all the other markup and information that we want to show up in the document will be between the starting <article> tag and the ending </article> tag. The real structure of your document is created with the <sectX> tags. Let's add some more section tags and also do some nesting of <sectX> tags. (where X is a number between 1 and 5.) For example, here we have 3 sections:

 
<!-- license cut out for clarity -->
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
<article>
   <sect1 id="introduction"><title>Hello world introduction</title>
      <para>
      Hello world!
      </para>
   </sect1>

   <sect1 id="main-body"><title>Main Body</title>
      <para>
      This is the main body
      </para>
   </sect1>

   <sect1 id="conclusion"><title>Conclusion</title>
      <para>
      In conclusion...
      </para>
   </sect1>
</article>

Now we will add a few subsections by nesting some <sectX> tags. Below is an example and explanation of the code:

 
<!-- license cut out for clarity -->
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
<article>
   <sect1 id="introduction"><title>Hello world introduction</title>
      <para>
      Hello world!
      </para>

      <sect2 id="credits"><title>Credits</title>
         <para>
         I would like to take this time to thank the creators of Linux!
         </para>
      </sect2>
   </sect1>

   <sect1 id="main-body"><title>Main Body</title>
      <para>
      This introduces the main body
      </para>

      <sect2 id="point1"><title>Point1</title>
         <para>
         My first point is ...
         </para>
      </sect2>

      <sect2 id="point2"><title>Point2</title>
         <para>
         My second point is ...
         </para>
      </sect2>
   </sect1>

   <sect1 id="conclusion"><title>Conclusion</title>
      <para>
      In conclusion...
      </para>
   </sect1>
</article>

This would create a subsection under the Introduction called Credits, Point1 under the Main Body, and Point2 under the Main Body. You can nest these sections any way you see fit. The only limitation is you can not nest any deeper then <sect5>. You must also remember that you can only nest <sectX> tags with a higher number. In other words, you can not nest a <sect1> tag inside a <sect2> tag. You could nest a <sect3>, <sect4>, or <sect5> tag inside a <sect2> tag but not a <sect1>.

If you render this document, you will see that the HTML files created match the <sect1> elements!