XML output from MACSEC related show commands is incorrectly structured. The interface name keys are returned at the same level of the tree as the keys for that interface.
The only way to associate an interface with the information for that interface is to sequentially read the output line by line and do extra processing, which mostly defeats the purpose of using structured data.
Below we see 2 interfaces with MACSEC configured here, et-1/1/3 , et-8/0/3 and the XML output for show security mka statistics has every node at the same tree level, meaning there is no relationship between them, in the XML construct.
labroot@prescott-re0> show security mka statistics | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/20.3R0/junos">
<mka-statistics>
<interface-name>et-1/1/3</interface-name>
<received-packets>636</received-packets>
<sent-packets>633</sent-packets>
<version-error>0</version-error>
<cak-error>0</cak-error>
<integrity-check-value-mismatch>0</integrity-check-value-mismatch>
<duplicate-message-identifier>0</duplicate-message-identifier>
<duplicate-message-number>0</duplicate-message-number>
<duplicate-address>0</duplicate-address>
<invalid-destination>0</invalid-destination>
<format-error>0</format-error>
<old-message-number>0</old-message-number>
<interface-name>et-8/0/3</interface-name>
<received-packets>0</received-packets>
<sent-packets>14</sent-packets>
</mka-statistics>
<cli>
<banner>{master}</banner>
</cli>
</rpc-reply>
labroot@prescott-re0> show security mka statistics
Interface name: et-1/1/3
Received packets: 639
Transmitted packets: 636
Version mismatch packets: 0
CAK mismatch packets: 0
ICV mismatch packets: 0
Duplicate message identifier packets: 0
Duplicate message number packets: 0
Duplicate address packets: 0
Invalid destination address packets: 0
Formatting error packets: 0
Old Replayed message number packets: 0
Interface name: et-8/0/3
Received packets: 0
Transmitted packets: 17
Formatting error packets: 0 Old Replayed message number packets: 0
The behavior is changed/ fixed starting Junos 22.4R3 onwards.
The fixed/corrected output should look like below where there is one node for each physical-interface ge-0/0/0 and ge-0/0/2, with child elements below it that contain all the relevant data for that interface only.
root@vmx1# run show security mka statistics | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/24.2I20240213_0528_ndebnath/junos">
<mka-interface-statistics>
<interface-name>ge-0/0/0</interface-name>
<received-packets>18</received-packets>
<sent-packets>17</sent-packets>
<cak-error>1</cak-error>
</mka-interface-statistics>
<interface-name>ge-0/0/2</interface-name>
<received-packets>98</received-packets>
<sent-packets>229</sent-packets>
<banner>[edit]</banner>
2024-07-25 : Initial publication