Hi Marc,
Like others in this thread, we also had this requirement. We ended up using the Cognos REST API for retrieving the report specifications and I then wrote some R code extracting the data item expressions using the xml2 package. We are using a DMR package, which possibly leads to a greater number of data item types that need to be handled. I provide a code snippet below that shows how I have extracted the text of nodes that directly contain identifiers (MUN/LUN/MPUN) vs. extracting the text for parent nodes that contain <expression> children. The code certainly isn't bulletproof, but it may be helpful to some. I am happy to elaborate further, if desired.
get_data_item_expressions <- function(xml, ns) {
if (!inherits(xml, "xml_document") && !inherits(xml, "xml_node")) {
stop("`xml` must be an xml2 document/node")
}
# XPaths that directly contain identifier texts (MUN/LUN/MPUN)
data_items_with_identifiers <- c(
"//cognos:dataItemMeasure//cognos:MUN",
"//cognos:dataItemSet//cognos:MUN",
"//cognos:dataItemLevelSet//cognos:LUN",
"//cognos:dataItemMember//cognos:MUN",
"//cognos:dataItemMemberProperty//cognos:MPUN"
)
id_nodes <- xml2::xml_find_all(
xml,
xpath = stringr::str_c(
data_items_with_identifiers,
collapse = " | "
),
ns = ns
)
id_texts <- if (length(id_nodes) > 0) stringr::str_squish(xml2::xml_text(id_nodes)) else character(0)
# Parent nodes that may contain <expression> children
data_items_with_expressions <- c(
"//cognos:dataItem",
"//cognos:dataItemCalculatedMeasure",
"//cognos:dataItemSetExpression"
)
parent_nodes <- xml2::xml_find_all(
xml,
xpath = stringr::str_c(
data_items_with_expressions,
collapse = " | "
),
ns = ns
)
expr_nodes <- if (length(parent_nodes) > 0) {
xml2::xml_find_all(parent_nodes, ".//cognos:expression", ns = ns)
} else {
xml2::xml_find_all(xml, ".//cognos:expression", ns = ns) # fallback: search whole doc
}
expr_texts <- if (length(expr_nodes) > 0) stringr::str_squish(xml2::xml_text(expr_nodes)) else character(0)
data_item_expressions <- c(
id_texts,
expr_texts
)
return(data_item_expressions)
}
------------------------------
Richard Meyer-Eppler
------------------------------
Original Message:
Sent: Wed October 29, 2025 12:55 PM
From: Michael Webb
Subject: Report Data Item Usage
Hi Marc,
I developed a tool that parses all the reports found in a cognos folder and outputs a csv with all the data items, aliases, and query sources as a part of a metadata project we had at work. If you are interested we could meet and I could share the tool with you. Its a little finnicky but I think solves exactly your use case. It runs client side in the browser and uses Cognos expressbus api to retrieve all reports in a given folder. It can parse about 300 reports in 2 minutes or so.
------------------------------
Michael Webb
Original Message:
Sent: Tue October 28, 2025 11:52 AM
From: Marc Reed
Subject: Report Data Item Usage
Can anyone think of a clever way of identifying which data items a report uses? I have a bunch of reports specs saved as XML files. I am looking for something that would parse each file and extract the data items that are used. These are Framework Manager sourced reports so the data items would be in the format [*].[*].[*].
I know Framework Manager has a report usage tool - but that is tackling the problem from the full list of data items. FM could have 10,000 data items but the reports only use three on them hence me wanting to tackle the problem from the report spec side.
------------------------------
Marc Reed
Reporting Lead
------------------------------