How to automatically detect a namespace in the root label, to then extract its value into a variable and be able to loop through the elements

I want to extract elements with namespace “cac”, but I want detect with something functions to xDoc or something like that to get the value: “urn:oasis…”

xmlns:cac=“urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2”