# Buggy code
def _set_elements(self, root):
    """wrap objectified xml part with selection of elements to
    self.elements list
    """
    try:
        elements = root.find(
            "./ClassInstance[@Type='TRTContainerClass']"
            "/ChildClassInstances"
            "/ClassInstance[@Type='TRTElementInformationList']"
            "/ClassInstance[@Type='TRTSpectrumRegionList']"
            "/ChildClassInstances"
        )
        for j in elements.findall("./ClassInstance[@Type='TRTSpectrumRegion']"):
            tmp_d = dictionarize(j)
            self.elements[tmp_d["XmlClassName"]] = {
                "line": tmp_d["Line"],
                "energy": tmp_d["Energy"],
                "width": tmp_d["Width"],
            }
    except AttributeError:
        _logger.info("no element selection present in the spectra..")


# Traceback (KeyError)
KeyError                                  Traceback (most recent call last)
<ipython-input-6-ad1ad3391a64> in <module>
----> 1 b=hs.load('20190723_bon_accord_BCF_data/Mapping_(1,1).bcf')
~\AppData\Local\conda\conda\envs\hyperspy\lib\site-packages\hyperspy\io.py in
load(filenames, signal_type, stack, stack_axis, new_axis_name, lazy, convert_units, **kwds)
279             objects = [load_single_file(filename, lazy=lazy,
280                                         **kwds)
--> 281                        for filename in filenames]
282
283         if len(objects) == 1:`

~\AppData\Local\conda\conda\envs\hyperspy\lib\site-packages\hyperspy\io.py in
<listcomp>(.0)
279             objects = [load_single_file(filename, lazy=lazy,
280                                         **kwds)
--> 281                        for filename in filenames]
282
283         if len(objects) == 1:

~\AppData\Local\conda\conda\envs\hyperspy\lib\site-packages\hyperspy\io.py in
load_single_file(filename, **kwds)
316     else:
317         reader = io_plugins[i]
--> 318         return load_with_reader(filename=filename, reader=reader, **kwds)
319
320

~\AppData\Local\conda\conda\envs\hyperspy\lib\site-packages\hyperspy\io.py in
load_with_reader(filename, reader, signal_type, convert_units, **kwds)
323     lazy = kwds.get('lazy', False)
324     file_data_list = reader.file_reader(filename,
--> 325                                         **kwds)
326     objects = []
327

~\AppData\Local\conda\conda\envs\hyperspy\lib\site-
packages\hyperspy\io_plugins\bruker.py in file_reader(filename, *args, **kwds)
1189     ext = splitext(filename)[1][1:]
1190     if ext == 'bcf':
-> 1191         return bcf_reader(filename, *args, **kwds)
1192     elif ext == 'spx':
1193         return spx_reader(filename, *args, **kwds)

~\AppData\Local\conda\conda\envs\hyperspy\lib\site-
packages\hyperspy\io_plugins\bruker.py in bcf_reader(filename, select_type, index,
downsample, cutoff_at_kV, instrument, lazy)
1217
1218     # objectified bcf file:
-> 1219     obj_bcf = BCF_reader(filename, instrument=instrument)
1220     if select_type == 'spectrum':
1221         select_type = 'spectrum_image'

~\AppData\Local\conda\conda\envs\hyperspy\lib\site-
packages\hyperspy\io_plugins\bruker.py in __init__(self, filename, instrument)
883         hd_bt_str = fix_dec_patterns.sub(b'\\1.\\2', header_byte_str)
884         self.header = HyperHeader(
--> 885             hd_bt_str, self.available_indexes, instrument=instrument)
886         self.hypermap = {}
887

~\AppData\Local\conda\conda\envs\hyperspy\lib\site-
packages\hyperspy\io_plugins\bruker.py in __init__(self, xml_str, indexes, instrument)
586         self._set_images(root)
587         self.elements = {}
--> 588         self._set_elements(root)
589         self.line_counter = interpret(root.find('./LineCounter').text)
590         self.channel_count = int(root.find('./ChCount').text)

~\AppData\Local\conda\conda\envs\hyperspy\lib\site-
packages\hyperspy\io_plugins\bruker.py in _set_elements(self, root)
729                 self.elements[tmp_d['XmlClassName']] = {'line': tmp_d['Line'],
730                                                         'energy': tmp_d['Energy'],
--> 731                                                         'width': tmp_d['Width']}
732         except AttributeError:
733             _logger.info('no element selection present in the spectra..')

KeyError: 'Width'`

# Fixed code
def _set_elements(self, root):
    """wrap objectified xml part with selection of elements to
    self.elements list
    """
    try:
        elements = root.find(
            "./ClassInstance[@Type='TRTContainerClass']"
            "/ChildClassInstances"
            "/ClassInstance[@Type='TRTElementInformationList']"
            "/ClassInstance[@Type='TRTSpectrumRegionList']"
            "/ChildClassInstances"
        )
        for j in elements.findall("./ClassInstance[@Type='TRTSpectrumRegion']"):
            tmp_d = dictionarize(j)
            self.elements[tmp_d["XmlClassName"]] = {
                "line": tmp_d["Line"],
                "energy": tmp_d["Energy"],
            }
    except AttributeError:
        _logger.info("no element selection present in the spectra..")