Skip to content

Instantly share code, notes, and snippets.

@cra
Created January 4, 2024 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cra/4f333af478e64dfdf19ebcc75a41068d to your computer and use it in GitHub Desktop.
Save cra/4f333af478e64dfdf19ebcc75a41068d to your computer and use it in GitHub Desktop.
from datetime import datetime as dt
from airflow.decorators import task, dag
@dag(schedule=None, start_date=dt(2024, 1, 1))
def vlad_xml_find():
@task
def open_xml():
import xml.etree.ElementTree as ET
tree = ET.parse('/tmp/testXML.xml')
# cat /tmp/testXML.xml
# <?xml version="1.0" encoding="UTF-8"?><xml-response><action>Review</action></xml-response>
tree = tree.getroot()
t = ET.tostring(tree)
t = t.lower()
xml = ET.fromstring(t)
print('iterating')
print('1. findall')
for i in xml.findall('./{*}action'):
print(i.text)
print('...')
print('2. itertext')
for item in xml.itertext():
print(item)
open_xml()
_ = vlad_xml_find()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment