XML technologies / DocBook / Modular documents / Including content with XIncludes / Using XInclude

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

To insert individual files into a DocBook document using XIncludes, place the element xi:include at the appropriate location. The example below shows a master file and a reference to a chapter.

Example: Chapter to include: file docbook-intro.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Die einzufügende Datei darf eine DOCTYPE-Deklaration besitzen: -->
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd">
<chapter id="docbook-intro">
  <title>Einführung in DocBook</title>
  ...
</chapter>

 

Example: Master file as a book: file book.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd">
<book>
 <title>DocBook-XML</title>
 <para>...</para>
 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="docbook-intro.xml" />
  ... 
</book>

Line 6: Namespace declaration (with namespace prefix xi) for XInclude. The URI "http://www.w3.org/2001/XInclude" must be written exactly this way for replacement to work; case matters. The xi:include element requires the attribute href, which contains a URI pointing to the file docbook-intro.xml.

In this example, the XML parser attempts to read the file docbook-intro.xml. If successful, the include element is replaced by the content of docbook-intro.xml. If it fails, the parser issues a message.

  

back to top