Chapter 3. Text inclusions

The general form of a text inclusion is:

<xi:include xmlns:xi='http://www.w3.org/2001/XInclude'
            href='/path/to/document.txt'
            parse='text'
            fragid='text(?)'/>

The parse attribute must be present and must have the value text, that’s what makes it a text inclusion. The fragment identifier is also optional; if it’s not present, the entire document is included. The attribute xpointer can be used instead of fragid, but that’s discouraged because technically an XPointer can only refer to an XML document.

Parsing the example from Chapter 2, XML inclusions as text, inserts the whole file:

Example 3.1. Text inclusion without a fragment identifier
<xi:include href="abstraction.xml" parse="text"/>
Subexample 3.1.1. The XInclude
<blockquote xmlns="http://docbook.org/ns/docbook" version="5.2">
<title>Abstraction</title>
<attribution><personname>Paul Hudak</personname></attribution>
<para xml:id="abs"><quote>Abstraction, abstraction and abstraction.</quote>
This is the answer to the question, <quote>What are the three most
important words in programming?</quote></para>
</blockquote>
Subexample 3.1.2. What’s included

3.1. XML fragment identifier schemes

char=

A char= fragment identifier is interpreted according to RFC 5147 with integrity checking.

Example 3.2. Text inclusion with a char identifier
<xi:include href="abstraction.xml" parse="text" fragid="char=68,87"/>
Subexample 3.2.1. The XInclude
tle>Abstraction</ti
Subexample 3.2.2. What’s included
line=

A line= fragment identifier is interpreted according to RFC 5147 with integrity checking.

Example 3.3. Text inclusion with a line identifier
<xi:include href="abstraction.xml" parse="text" fragid="line=3,5"/>
Subexample 3.3.1. The XInclude
<para xml:id="abs"><quote>Abstraction, abstraction and abstraction.</quote>
This is the answer to the question, <quote>What are the three most
Subexample 3.3.2. What’s included
L#-L#

This scheme is the loosely documented format supported by GitHub. It identifies a line or range of lines, for example L3 identifies line 3 and L3-L7 identifies lines 3 through 7, inclusive.

Example 3.4. Text inclusion with a L#-L# identifier
<xi:include href="abstraction.xml" parse="text" fragid="L3-L5"/>
Subexample 3.4.1. The XInclude
<attribution><personname>Paul Hudak</personname></attribution>
<para xml:id="abs"><quote>Abstraction, abstraction and abstraction.</quote>
This is the answer to the question, <quote>What are the three most
Subexample 3.4.2. What’s included
search=

The search= fragment identifier locates lines by searching within the text.

Example 3.5. Text inclusion with a searchidentifier
<xi:include href="abstraction.xml" parse="text"
            fragid="search=/&lt;para/,#/para#"/>
Subexample 3.5.1. The XInclude
<para xml:id="abs"><quote>Abstraction, abstraction and abstraction.</quote>
This is the answer to the question, <quote>What are the three most
important words in programming?</quote></para>
Subexample 3.5.2. What’s included

3.1.1. RFC 5147 integrity checking

Both the char= and line= flavors of RFC 5147 identifiers (and the search= extension scheme) support either file size or MD5 integrity checking. This fragment identifier: line=23,67;length=3134 will fail unless the file identified is 3,134 bytes long. Alternatively, line=23,67;md5=135b35933056ba8d06e8d3f5f4ecd318 will fail unless the file has an MD5 message digest equal to 135b35933056ba8d06e8d3f5f4ecd318.

Example 3.6. Text inclusion with integrity checking
<xi:include href="abstraction.xml" parse="text"
            fragid="line=3,5;md5=d6090e3280649716833e3c33269d1892"/>
Subexample 3.6.1. The XInclude
<para xml:id="abs"><quote>Abstraction, abstraction and abstraction.</quote>
This is the answer to the question, <quote>What are the three most
Subexample 3.6.2. What’s included

Many systems come with a program named md5 that will compute the MD5 hash of a file:

$ md5 abstraction.xml
MD5 (abstraction.xml) = d6090e3280649716833e3c33269d1892

Alternatively, you can specify an incorrect hash in the fragment identifier and SInclude will tell you what it was expecting when the integrity check fails.