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
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 forparaare listed in the parameter entity%para.char.mix;(filedbpoolx.mod). It references other Parameter Entities, grouping similar elements, such as%xref.char.class;,%gen.char.class;,%tech.char.class;. The new elementipaddressfits the technical category, so choose the last one.Customizing
%tech.char.class;
Create a new file, for exampledb-ipaddress.dtd. To customize%tech.char.class;you need%local.tech.char.class;:
<!ENTITY % local.tech.char.class "|ipaddress">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;Defining
ipaddress
Define the new elementipaddresswith these lines. It includes the standard attributes defined in%common.attrib;:
<!ELEMENT ipaddress (#PCDATA)>
<!ATTLIST ipaddress %common.attrib;>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
Find the appropriate definition pattern
Finding a suitable definition pattern is the hardest part. Determine whichdb.*.inlinespattern best fits the element (see the table Naming conventions for DocBook 5). Several options may suit your requirements, such asdb.technical.inlines,db.extension.inlinesor others. This example assumes the definition patterndb.technial.inlines.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: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
} Using the customization file
Use the customization file instead of the original DocBook file (see Validating with a DocBook 5 customization file).
Copyright © 2009 Millin Verlag
You may print the online version for your private use.
Otherwise, this chapter from "DocBook-XML: Medienneutrales und plattformunabhängiges Publizieren" is subject to the same provisions as the printed edition: the work, including all its parts, is protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Millin Verlag, Siebengebirgsring 36, 53797 Lohmar, info(at)millin.de