Skip to content

Instantly share code, notes, and snippets.

@daaniam
Last active December 6, 2022 14:22
Show Gist options
  • Save daaniam/00846497d044ac063cf17047d67f3b93 to your computer and use it in GitHub Desktop.
Save daaniam/00846497d044ac063cf17047d67f3b93 to your computer and use it in GitHub Desktop.
example: Locate xml element
def extract_files_from_xml(xml_element: etree.Element) -> list[BytesIO]:
"""Extract files from XML element"""
output = []
elements_with_file = ["bArray", "ByteArray"]
for file_element in elements_with_file:
# Locate element
for element_with_file in xml_element.xpath(f'//*[local-name()="{file_element}"]'):
print('element with file', element_with_file)
# Add found element to output
output.append(BytesIO(element_with_file))
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment