# Buggy code
def __init__(self, xml_str, instrument=None):
    root = ET.fromstring(xml_str)
    root = root.find("./ClassInstance[@Type='TRTSpectrumDatabase']")
    try:
        self.name = str(root.attrib["Name"])
    except KeyError:
        self.name = "Undefinded"
        _logger.info("hypermap have no name. Giving it 'Undefined' name")
    hd = root.find("./Header")
    dt = datetime.strptime(
        " ".join([str(hd.find("./Date").text), str(hd.find("./Time").text)]),
        "%d.%m.%Y %H:%M:%S",
    )
    self.date = dt.date().isoformat()
    self.time = dt.time().isoformat()
    self.version = int(hd.find("./FileVersion").text)
    # fill the sem and stage attributes:
    self._set_microscope(root)
    self._get_mode(instrument)
    self._set_images(root)
    self.elements = {}
    self._set_elements(root)
    self.line_counter = interpret(root.find("./LineCounter").text)
    self.channel_count = int(root.find("./ChCount").text)
    self.mapping_count = int(root.find("./DetectorCount").text)
    # self.channel_factors = {}
    self.spectra_data = {}
    self._set_sum_edx(root)


# Traceback (IndexError)
hs.load(filename)
Traceback (most recent call last):

File "<ipython-input-3-ada763a7934e>", line 1, in <module>
hs.load(filename)

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io.py", line 243, in load
for filename in filenames]

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io.py", line 243, in <listcomp>
for filename in filenames]

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io.py", line 286, in load_single_file
**kwds)

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io.py", line 295, in load_with_reader
**kwds)

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io_plugins\bcf.py", line 1189, in file_reader
obj_bcf = BCF_reader(filename, instrument=instrument)

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io_plugins\bcf.py", line 876, in __init__
self.header = HyperHeader(header_byte_str, instrument=instrument)

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io_plugins\bcf.py", line 585, in __init__
self._set_sum_edx(root)

File "C:\ProgramData\Anaconda3\lib\site-packages\hyperspy\io_plugins\bcf.py", line 735, in _set_sum_edx
str(i))[0].ClassInstance)

IndexError: list index out of range

# Fixed code
def __init__(self, xml_str, indexes, instrument=None):
    root = ET.fromstring(xml_str)
    root = root.find("./ClassInstance[@Type='TRTSpectrumDatabase']")
    try:
        self.name = str(root.attrib["Name"])
    except KeyError:
        self.name = "Undefinded"
        _logger.info("hypermap have no name. Giving it 'Undefined' name")
    hd = root.find("./Header")
    dt = datetime.strptime(
        " ".join([str(hd.find("./Date").text), str(hd.find("./Time").text)]),
        "%d.%m.%Y %H:%M:%S",
    )
    self.date = dt.date().isoformat()
    self.time = dt.time().isoformat()
    self.version = int(hd.find("./FileVersion").text)
    # fill the sem and stage attributes:
    self._set_microscope(root)
    self._get_mode(instrument)
    self._set_images(root)
    self.elements = {}
    self._set_elements(root)
    self.line_counter = interpret(root.find("./LineCounter").text)
    self.channel_count = int(root.find("./ChCount").text)
    self.mapping_count = int(root.find("./DetectorCount").text)
    # self.channel_factors = {}
    self.spectra_data = {}
    self._set_sum_edx(root, indexes)