How are navigation elements and tables of contents (TOCs) linked in DITA XML?

Linking navigation elements and tables of contents (TOCs) in DITA XML is essential to create a structured and user-friendly documentation experience. Here are common practices for achieving this:

1. Internal Links: In DITA, you can use internal links to connect different parts of your documentation. For instance, to link to a specific section within a topic, you can create a link using the <xref> element with an href attribute that references the unique ID of the target topic. This method ensures that when you generate output, the links correctly point to the desired location within your content.

2. Table of Contents (TOC): DITA allows you to generate tables of contents that automatically list and link to various topics or sections in your documentation. You can use the <toc> element to define the structure of the TOC. For example, you can specify which topics to include, the hierarchical organization, and whether to display titles. When you generate output, the TOC reflects the structure you’ve defined and provides easy navigation for readers.


<!-- Example of internal link and TOC in DITA -->
<section id="introduction">
  <title>Introduction</title>
  <p>This is the introduction to our product.</p>
</section>

<section id="features">
  <title>Features</title>
  <p>Our product offers the following features: <xref href="#feature-1"/>, <xref href="#feature-2"/>.</p>
</section>

<section id="feature-1">
  <title>Feature 1</title>
  <p>Details about Feature 1.</p>
</section>

<section id="feature-2">
  <title>Feature 2</title>
  <p>Details about Feature 2.</p>
</section>

<!-- Define a table of contents (TOC) -->
<toc>
  <title>Table of Contents</title>
  <tocentry>
    <topicref href="#introduction"/>
  </tocentry>
  <tocentry>
    <topicref href="#features"/>
    <tocentry>
      <topicref href="#feature-1"/>
    </tocentry>
    <tocentry>
      <topicref href="#feature-2"/>
    </tocentry>
  </tocentry>
</toc>

In this example, we have topics that are linked together using internal links (<xref>). Additionally, a table of contents (<toc>) is defined to list and link to these topics, providing a clear navigation structure for users when generating documentation output.