I have not dealt with XML in a decade or more. Thank you Palo Alto. I hate it.
The lesson of the last week is don't necessarily write Python (with LLMs) even though you can. There are also CLI tools that do the job better than you can.
https://xmlstar.sourceforge.net/ is available in Debian repos and Homebrew and LLMs know about it. Also xmllint
XMLStarlet Command Line XML Toolkit: News

XMLStarlet Command Line XML Toolkit