DocBook XML: Semantic Document Design and Structure

DocBook XML: Semantic Document Design and Structure

DocBook is a specialized XML language designed for the creation of technical documentation. Unlike traditional formatting tools, DocBook operates as a semantic language. This means it focuses on the meaning and purpose of the content rather than its visual appearance. Instead of defining how a section should look, DocBook identifies what a section is—such as an abstract or a chapter—leaving the final visual presentation to external processing tools.

In its current 5.x version, DocBook is formally defined by a RELAX NG schema with integrated Schematron rules. While W3C XML Schema and Document Type Definition (DTD) versions exist, they are considered non-standard.

[ไม่มีภาพประกอบ]

Key Facts

  • Semantic Focus: Describes the meaning of content, not the visual layout.
  • Standard Schema: Formally defined using RELAX NG and Schematron.
  • Three Element Tiers: Organizes content into structural, block-level, and inline tags.
  • Processor Independence: External tools determine the final rendering (e.g., PDF, HTML).
  • Validation: Documents can be validated against schemas to ensure conformity.

The Hierarchy of DocBook Elements

DocBook provides a comprehensive library of semantic tags divided into three primary categories to organize information logically.

Structural Tags

Structural tags define the broad characteristics of the document. These are the only elements permitted at the top level of a DocBook document and can contain other structural elements.

  • set: A titled collection of one or more books or articles; these can be nested.
  • book: A titled collection of chapters, articles, and/or parts, which may include glossaries and appendices.
  • part: A titled collection of one or more chapters, potentially including introductory text and nesting capabilities.
  • article: A titled, unnumbered collection of block-level elements.
  • chapter: A titled, numbered collection of block-level elements. Numbers are calculated based on the sequence of chapter elements in the XML.
  • appendix: Contains supplementary text.
  • dedication: Text representing the dedication of the structural element.

Block-Level Tags

Block-level tags, such as paragraphs and lists, organize content sequentially. DocBook remains neutral regarding language-based directionality. While Western languages typically render blocks from top to bottom, other systems (like Japanese) may render them in columns from right to left. The semantic meaning remains the same regardless of the final visual flow.

Inline-Level Tags

Inline tags, such as hyperlinks and emphasis, wrap text within block-level elements. They do not cause line breaks but signal to the document processor that a distinct typographical treatment is required. For example, an emphasis tag might be rendered as italics by one processor or as bold text by another.

[ไม่มีภาพประกอบ]

Document Implementation and Validation

A typical DocBook document begins with a root element, such as <book>. Because DocBook uses an XML Namespace, the root element must include an xmlns attribute and a version attribute to specify the format version used.

For a <book> element to be valid, it must contain a <title> or an <info> element containing a title before any other structural children. Subsequent elements, such as chapters, must also include their own titles before containing block-level elements like paragraphs (<para>).

Schema Validation

To ensure a document is correctly formed, programming tools can validate the XML against the DocBook schema. This process identifies where a document fails to conform to the rules. Additionally, XML editing tools use this schema information to prevent the creation of non-conforming documents during the writing process.

DocBook Element Summary
Category Purpose Examples
Structural Defines broad document architecture book, chapter, article, part
Block-level Organizes sequential content paragraph, lists
Inline Applies typographical treatment to text emphasis, hyperlinks

Frequently Asked Questions

What is the difference between a semantic language and a formatting language?

A semantic language like DocBook describes what the content is (e.g., "this is a chapter") rather than how it looks (e.g., "this text should be 24pt Arial"). The visual styling is handled by an external processor.

Which schema is the standard for DocBook 5.x?

The formal definition for DocBook 5.x is provided by a RELAX NG schema with integrated Schematron rules.

How are chapter numbers handled in DocBook?

Chapters do not require explicit numbers. The chapter number is automatically determined by counting the number of previous chapter elements in the XML document and adding one.

Can structural elements be nested?

Yes, certain structural elements can be nested. For example, a set can contain other sets, and a part can contain other parts.

Does an emphasis tag always result in italics?

No. The DocBook specification requires a distinct typographical treatment, but the specific style is decided by the processor. It could be rendered as italics, bold text, or a different font size.