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

if possible share the complete XML as textfile

Your queastion is unclear. We can avoid some code parts when working with xDoc.Root

xDoc.Root.Descendants(…