import re


def _out2list(xmldoc):
    """
    converts the xml output of condor_q into a list.
    This is in case the output is a multiple XML doc, 
    as it happens when condor_q -g 
    So each part of the output is one element of the list
    """

    # we assume the header of each part of the output starts
    # with string '<?xml version="1.0"?>'
    #indexes = [m.start() for m in re.finditer('<\?xml version="1.0"\?>',  xmldoc )]
    indexes = [m.start() for m in re.finditer('<\?xml',  xmldoc )]
    if len(indexes)==1:
        outs = [xmldoc]
    else:
        outs = []
        for i in range(len(indexes)):
            if i == len(indexes)-1:
                tmp = xmldoc[indexes[i]:]
            else:
                tmp = xmldoc[indexes[i]:indexes[i+1]]
            outs.append(tmp)
    return outs