from xml.dom.minidom import parse
import typing


def parse_element(stream: typing.BinaryIO):
    """Parse the content of the PSML file to determine the element.

    :param stream: a filelike object with the binary content of the file.
    :return: the symbol of the element following the IUPAC naming standard.
    """

    try:
        xml = parse(stream)
        element = xml.getElementsByTagName('pseudo-atom-spec')[0].attributes['atomic-label'].value
    except (AttributeError, IndexError, KeyError) as exception:
        raise ValueError(f'could not parse the element from the PSML content: {exception}') from exception

    return element.capitalize()