Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

DITA Semantic tests

Quick start

This assumes you know how to use venv and poetry.

  1. We recommend using venv
  2. Install dependencies by running poetry install
  3. Run each test in poetry: poetry run python semantic_testing/, etc.

Semantic testing is where DITA truly shines. But what is semantic testing?

A simple explanation is “using the semantics of DITA to test documentation”. What is semantics in DITA? It’s about the named tags and their relations to other tags in the document structure.

In contrast, there’s no semantics in Markdown. Let’s look at the following sample of Markdown.

# Running the converter

Run the following command:

./ “../images” png svg

**Result**: The `converter` creates images in the `out` directory.

The semantics of this sample is that there is a heading, a code sample, some text in bold (Result) and some words related to code sprinkled in the text ("converter" and "out"). This does not really convey a lot of semantics.

In DITA, the sample would look like this:

    <title>Running the converter</title>
                <cmd>Run the following command:</cmd>
                    <codeblock outputclass="sh">./ "../images" png svg</codeblock>
                    The <apiname>converter</apiname> creates images in the
                    <filepath>out</filepath> directory.

This example shows full semantics in DITA:

  • We know that the whole thing is a task which semantically means “something to do”.
  • The title is “Running the converter”. We could specify this further and say that “converter” is an API name. We could then establish a convention that the first word in a task title is an action verb. As a result, we could for example find all topics that contain the word “run” (or its synonyms, in any grammatical form) and grab them for tests.
  • There is also granular semantics that tell us about each step, user instruction, code sample, file path, and more.

All this semantics, or, in other words, all this meaning allows us to test the document semantically.

Running code samples in DITA topics

First, let’s get a list of synonyms of the word we’re looking for. In Python, we can use the nltk library:

from nltk.corpus import wordnet

def get_synonyms(word):
    synonyms = []
    for syn in wordnet.synsets(word):
        for l in syn.lemmas():
            synonym ='_', ' ')
            if synonym not in synonyms:
    return synonyms

The result for the word “run” should be something like:

  "running play",
  "running game",
  "turn tail",
  "run away",
  "hightail it",
  "head for the hills",
  "take to the woods",
  "fly the coop",
  "break away",
  "be given",
  "die hard",
  "black market",
  "run for",
  "hunt down",
  "track down",
  "melt down",

We can use glob and minidom to find out which tasks match our criteria.

path = './resources/dita/\*_/_.dita'

for file in glob.iglob(path, recursive=True):
    doc = minidom.parse(file)
    if doc.documentElement.tagName == 'task':
        title = doc.getElementsByTagName('title')[0].firstChild.nodeValue
        first_word = title.split()[0]
        if first_word.lower() in synonyms:
            print(f'"{title}" is a matching task, testing')
            print(f'We will not process {title}')

The tests could go like this:

  1. In the task, find each step that contains a codeblock.
  2. Run the code in the codeblock.
  3. If there is a filepath in the stepresult, check if that path was created.
path_to_check = None
filepaths = doc.getElementsByTagName("filepath")
if filepaths:
    path_in_topic = [
        for filepath in filepaths
        if filepath.getAttribute("outputclass") == "output_path"

    path_to_check = app_folder / path_in_topic

    if path_to_check and path_to_check.exists():

    command_to_run = doc.getElementsByTagName("codeblock")[0].firstChild.nodeValue

    stream = os.popen(command_to_run)
    output = stream.readlines()
    result = stream.close()
    if result:
        print(f"Problem running command {command_to_run}: {result}")
        check_command_output(output, command_to_run)

    if not path_to_check.exists():
        print(f"Specified output path does not exist: {path_to_check}")
        print(f"Path OK: {path_to_check}")

The full test is in the semantic_testing/ file.

Check if a file exists

The file resources/dita/reference.dita lists some files like this:


The simplest semantic test could be:

For each , verify if the file exists.

The code is in semantic_testing/, inside the check_filepath() function.

Parameters listed in configuration files

We can continue parsing resources/dita/reference.dita to check if each listed config file actually contains the properties we claim that it does:

            <pd>Level of image quality to preserve during conversion.</pd>

Our semantic test goes like this:

For each <pt>, verify if it exists in the file from <filepath>.

You can find it in semantic_testing/, in the check_param_list() function.


In Markdown, running a spellcheck is quite simple. The only rules to follow are:

  • Ignore letters between `
  • Ignore lines between ```

In DITA, you need to ignore content enclosed by tags like:

  • codeph
  • codeblock
  • apiname
  • filepath
  • option
  • etc.

You also need to specify rules like:

  • Except when they have a particular attribute,
  • Except in certain XML contexts,
  • etc.

This makes spellchecking DITA a little tricky. But you can see our example in semantic_testing\ Notice the list of excluded elements and ignored words.


No description, website, or topics provided.






No releases published


No packages published