Chapter 7. Describing the Application's Interface

Table of Contents

7.1. Examples
7.2. GUI Interface Elements
7.3. Command Line Elements
7.4. Elements for classes and methods
7.5. Describing an API

7.1. Examples

Often we want to include examples of source code, commands, or GUI actions in our documentation. DocBook has many tags to support these needs. Some of the relevant element are listed below.

  • example - Example of a computer program or related information

  • informalexample - Untitled example

  • literallayout - Wrapper for lines set off from the main text that are not tagged as screens, examples, or programlisting, in which line breaks and leading white space are to be regarded as significant

  • programlisting - Listing of all or part of a program

  • screen - Text that a user sees or might see on a computer screen

Example 7.1. An example

<title>A BASIC Example</title>
<programlisting linenumbering='numbered'>
20 GOTO 10

In this first example, we have a listing of a simple BASIC program. The code contained in the programlisting element is displayed with the spacing and line breaks intact which is very useful for code examples and similar situations where you must preserve the literal formatting. The literallayout and screen elements work similarly, but they are used to indicate different types of content, in particular screen elements contain output that would appear on the screen, while literallayout elements are used for any other text that must be rendered with line breaks and tabs.

The example would look something like this when converted:

Example 7.2. A BASIC Example

  3 20 GOTO 10

One problem with the screen , literallayout , and programlisting elements is that all text is rendered literally, but DocBook tags are still interpreted as tags and not text. If you do not want tags and entity references interpreted, you can use a <![ CDATA [ ]]> section, which labels the text contained within the inner brackets as character data that should not be interpreted by the XML parser. Any text within the brackets will remain as-is after the conversion, so the example above will successfully reproduce its tags.

Example 7.3. Displaying markup in a CDATA section

<title>CDATA sections and markup</title>
<para>This is a DocBook example.</para>

This is what the markup example would look like when converted:

Example 7.4. CDATA sections and markup

<para>This is a DocBook example.</para>