Created
January 4, 2024 12:58
-
-
Save cra/4f333af478e64dfdf19ebcc75a41068d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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