def fix_xml(data):
    """Cleans up XML to prevent XML parsing errors"""

    #removes newline characters from reading file as one string with read()
    data = data.replace('\n', '')
    
    # sometimes console output is logged to remove everything before the first <rpc-reply> tag
    find_text = "<rpc-reply"
    k = data.rfind(find_text)
    data = data[k:]

    # removes everything after the last </rpc-reply>
    find_text = "</rpc-reply>"
    k = data.rfind(find_text)
    k += len(find_text)
    data = data[:k]

    return data