[Python] Python parse id attribute instead of element from xml

Discussão em 'Python' iniciado por Stack, Janeiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    This python code processed some xml data as shown in the comment

    # <members><id>26</id><name>Alexi Delano</name><id>27</id><name>Cari Lekebusch</name></members>
    def element_members(self, element):
    for id, name in grouper([child.text for child in element.iterchildren()], 2):
    yield int(id), name.strip()


    Now the xml data has removed the id element and make it an attribute instead

    # <members><name id="26">Alexi Delano</name><name id="27">Cari Lekebusch</


    so the code no longer works

    I can see i need to remove the id from for id but I cannot work out to get from attribute instead

    This is an opensrc project on github and the complete source file is here

    Continue reading...

Compartilhe esta Página