ArcGIS Server WMS's services gruops layers in layer 'folders', an them as a tree structure. Possible validation: from capabilities, take as layers only <layer> nodes that don't have any <layer> node within.