XML technologies / DocBook / Customizing DocBook / Adding elements / Adding an inline element

(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)

Suppose network documentation needs an element for IP addresses. This section adds the new element ipaddress inside para. To keep the example simple, ipaddress may contain only text.

Customizing DocBook 4

For DocBook 4, proceed as follows:

Procedure: Adding ipaddress in para for DocBook 4

  1. Find the appropriate parameter entity for the inline element
    First identify the category for the new element, often the hardest part because you must explore the DocBookDTD. All inline elements for para are listed in the parameter entity %para.char.mix; (file dbpoolx.mod). It references other Parameter Entities, grouping similar elements, such as %xref.char.class;, %gen.char.class;, %tech.char.class;. The new element ipaddress fits the technical category, so choose the last one.

  2. Customizing %tech.char.class;
    Create a new file, for example db-ipaddress.dtd. To customize %tech.char.class; you need %local.tech.char.class;:

<!ENTITY % local.tech.char.class "|ipaddress">

  1. Loading the DocBook DTD
    Add these lines to load the DocBook DTD:

<!ENTITY % DocBookDTD PUBLIC 
   "-//OASIS//DTD DocBook XML V4.5//EN" 
   "http://www.docbook.org/xml/4.5/docbookx.dtd"> 
%DocBookDTD;

  1. Defining ipaddress
    Define the new element ipaddress with these lines. It includes the standard attributes defined in %common.attrib;:

<!ELEMENT ipaddress (#PCDATA)>
<!ATTLIST ipaddress %common.attrib;>

  1. Using the customization file
    Use the customization file instead of the original DocBook file (see Validating with a DocBook 4 customization file).

Customizing DocBook 5

For DocBook 5, proceed as follows:

Procedure: Adding ipaddress in para for DocBook 5

  1. Find the appropriate definition pattern
    Finding a suitable definition pattern is the hardest part. Determine which db.*.inlines pattern best fits the element (see the table Naming conventions for DocBook 5). Several options may suit your requirements, such as db.technical.inlines, db.extension.inlines or others. This example assumes the definition pattern db.technial.inlines.

  2. Creating the customization file
    Create a customization file with this content:

<grammar ns="http://docbook.org/ns/docbook" xmlns:db="http://docbook.org/ns/docbook" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0">   
  <include href="docbook.rng"/> 
  <define name="db.technical.inlines" combine="choice"> 
    <ref name="db.ipaddress"/> 
  </define> 
  <!-- Definieren des ipaddress Elements: --> 
</grammar>

default namespace db = "http://docbook.org/ns/docbook" 

include "docbook.rnc" 

db.technical.inlines |= db.ipaddress 

# Definieren des ipaddress Elements:

  1. Defining ipaddress
    Finally, add the new element after the preceding comment. Follow the DocBook 5 schema’s naming and conventions so that downstream customizations can adapt it:

<define name="db.ipaddress.role.attribute"> 
    <attribute name="role"/> 
</define> 
<define name="db.ipaddress.attlist"> 
    <interleave> 
        <optional> 
            <ref name="db.ipaddress.role.attribute"/> 
        </optional> 
        <ref name="db.common.attributes"/> 
        <ref name="db.common.linking.attributes"/> 
    </interleave> 
</define> 
<define name="db.ipaddress"> 
    <element name="ipaddress"> 
        <ref name="db.ipaddress.attlist"> 
            <a:documentation>An IP adress</a:documentation> 
        </ref> 
        <text/> 
    </element> 
</define>

db.ipaddress.role.attribute = attribute role { text } 
db.ipaddress.attlist = 
   db.ipaddress.role.attribute? 
 & db.common.attributes 
 & db.common.linking.attributes

db.ipaddress = 
   element ipaddress { 
     ## An IP adress 
     db.ipaddress.attlist, 
     text 
  } 

  1. Using the customization file
    Use the customization file instead of the original DocBook file (see Validating with a DocBook 5 customization file).

  

back to top