[Fixed]-Iterate Over XML Response With ElementTreee Django

1👍

As mentioned in the documentation, iterparse() returns (event, elem) pairs (notice the order). Your code has event and elem variables in the wrong order, that’s why it always print end from “end” event. Correct the ordering, then you can check current element name from elem.tag and get value of the element from elem.text :

for event, elem in items:
    print(elem.tag, elem.text)
👤har07

Leave a comment