Auto-insert data into a DITA XML file
We want to automate the generation of the following DITA file:
<?xml version = "1.0" encoding = "utf-8"?><!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA 1.2 Topic//EN" "/usr/share/dita-ot/dtd/technicalContent/dtd/topic.dtd"><topic id="products-and-versions"> <title>Products and versions</title> <body> <p>Dianthus</p> <ul> <li>1.0</li> <li>1.5</li> <li>2.3</li> </ul> <p>Geum</p> <ul> <li>1.0</li> <li>1.5</li> <li>2.3</li> </ul> <p>Prunus</p> <ul> <li>1.0</li> <li>1.5</li> <li>2.3</li> </ul> </body></topic>-
Install the following programs and libraries:
Terminal window $ sudo apt install libxml2-dev libxslt1-dev python3-lxml -
Create the following Python script
populate-xml.py:code/populate-xml.py -
Make the script executable, then run it:
Terminal window $ chmod +x populate-xml.py$ ./populate-xml.pyThe
template.ditafile is created and contains the desired data.
This approach minimizes the risk of errors and reduces the effort involved in updating.