XML technologies / DocBook / Modular documents / Including content with XIncludes / Handling errors

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

If loading a resource causes an error, fallback handles it. Inside fallback you may insert anything also permitted in place of include: either elements or text.

If the example ‘Combined file as a book: file book.xml’ is extended with the element fallback, it becomes:

Example: Handling errors with xi:fallback

<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="docbook-intro.xml">
    <xi:fallback>
        <para>
            <emphasis>Datei docbook-intro.xml nicht gefunden!</emphasis>
        </para>
    </xi:fallback>
</xi:include>

If docbook-intro.xml is not found, a paragraph is inserted there. After resolving XInclude, the file looks as follows:

<para>
   <emphasis>Datei docbook-intro.xml nicht gefunden!</emphasis>
</para>

Note that the document must be valid after resolution. In place of xi:include a para element is allowed, but not an emphasis element. Therefore, the following xi:include element produces an invalid document:

<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="docbook-intro.xml">
    <xi:fallback>
        <emphasis>Datei docbook-intro.xml nicht gefunden!</emphasis>
    </xi:fallback>
</xi:include>

  

back to top