#### 10.2.2 Including external code snippets with fragment identifiers

You can use RFC 5147 fragment identifier syntax in the href attribute value to select portions of code or text from an external file. The following two examples produce the same result:

With a processing instruction

    <?dtall ExtCodeStartLine="4" ExtCodeEndLine="15"
      ExtCodeFileLen="438" ExtCodeFileEnc="UTF-8" ?>
    <codeblock><coderef href="fdkfunc.c" /></codeblock>

With a fragment identifier

    <codeblock><coderef
      href="fdkfunc.c#line=3,15;length=438,UTF-8" /></codeblock>

The fragment identifier is not required to have #topicID/elemID in <coderef> because the target file is not necessarily DITA, so the latter usage does not conflict with the DITA specification.

In RFC 5147, the starting line number is actually the line number before the first line you want, because it is zero-based; to start with the first line, you would use #line=,15. By contrast, DITA2Go PI markers remain one-based, just as all text editors do.

RFC 5147 does not say what to do if both line and character offsets are present. DITA2Go starts with the starting line, then counts to the starting character from that point, and continues until the ending character (relative to the same point), or the ending line, whichever is encountered first. This allows you to select a part of one or more lines easily, without having to count characters (which are code points, not bytes) to get to the starting line.

The file length (in bytes) provides a way to check whether the file has changed since you specified the offsets. This is the same check Norm Walsh makes in Calabash for the XInclude version. If the file size is provided and is not the same, DITA2Go logs an error and does not include any file content, per RFC 5147.

Previous Topic: 10.2.1 Including external code snippets with PI markers

Next Topic: 11. Defining element sets and properties

Parent Topic: 10.2 Referencing external code or text fragments

Sibling Topics:

10.2.1 Including external code snippets with PI markers