import re


def _getXMLText(fileobj):
    """Convenience function for reading the XML header data in a ShakeMap grid file.
    :param fileobj:
      File-like object representing an open ShakeMap grid file.
    :returns:
      All XML header text.
    """
    tline = fileobj.readline()
    datamatch = re.compile('grid_data')
    xmltext = ''
    tlineold = ''
    while not datamatch.search(tline) and tline != tlineold:
        tlineold = tline
        xmltext = xmltext + tline
        tline = fileobj.readline()

    xmltext = xmltext + '</shakemap_grid>'
    return xmltext