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

for name space handling have a look here:
XML Extraction - Handling Namespaces (Tableau, Soap, OASIS types) - Help / Community - UiPath Community Forum

for the document default namespace we can do:
grafik

For collecting all other namespace definitions we can do:

xDoc.Root.Attributes.where(Function (x) x.IsNamespaceDeclaration).Select(Function (x) x.Value).tolist

Creating some helpers e.g a dictionary with a key for the prefix and value as XNamespace we can do:


The document Default Namespace does not have a local name and we use the key xmlns for:

xDoc.Root.Attributes.where(Function (x) x.IsNamespaceDeclaration).ToDictionary( Function (x) x.Name.LocalName, Function (x) x.value)

Similiar we can also do on other XElements, when namespaces are defined there