[Doxygen] [Python] Doxygenのxmlファイルからファイル/関数一覧を抽出する

概要

Doxygenで出力したXML(index.xml)からPythonでファイル - 関数の一覧を抽出する。

コード

import xml.etree.ElementTree as ET

def extract_functions(xml_file):
    tree = ET.parse(xml_file)
    root = tree.getroot()

    functions = []

    # Iterate through compound elements (functions, classes, etc.)
    for compound in root.findall(".//compound[@kind='file']"):
        file_name = compound.find("name").text

        # Iterate through member elements (functions, variables, etc.)
        for member in compound.findall(".//member[@kind='function']"):
            function_name = member.find("name").text
            functions.append(f"{file_name}::{function_name}")

    return functions

if __name__ == "__main__":
    # Specify the path to the Doxygen XML output file
    doxygen_xml_file = "path/to/doxygen/xml/output.xml"

    # Extract functions
    function_list = extract_functions(doxygen_xml_file)

    # Print the list of functions
    for function in function_list:
        print(function)