What are key scopes in DITA XML?

In DITA XML, key scopes are an essential concept for managing keys, which are used to create cross-references, links, and references within your documentation. Key scopes define the scope or context within which keys are unique and accessible. Understanding key scopes is crucial for creating effective, organized, and unambiguous content that can be easily linked and referenced.

Defining Key Scopes

You can define key scopes at different levels, such as map, topic, or within a specific element. The scope you define determines where a key is unique and accessible. For example, if you define a key within a specific topic, that key will only be unique and accessible within that topic. However, if you define a key at the map level, it can be accessed across all topics within that map, making it useful for creating cross-references that span the entire documentation set.

Example:

Here’s an example of how key scopes can be defined in DITA XML:


<map>
  <title>Documentation Map</title>
  <keydef keys="key1 key2" href="topic1.dita" scope="map" />
  <keydef keys="key3 key4" href="topic2.dita" scope="topic" />
  <topicref href="topic1.dita" />
  <topicref href="topic2.dita" />
</map>

In this example, key scopes are defined at both the map and topic levels. Keys “key1” and “key2” are defined at the map level, making them accessible across all topics in the map. Keys “key3” and “key4” are defined at the topic level, restricting their scope to only the respective topics. This provides flexibility in managing keys based on your linking and referencing needs.