Often the XML has multiple nodes and we need to write a loop to process all of the nodes. In the following program, we loop through all of the user
nodes:
Code \(\PageIndex{1}\) (Python):
The findall
method retrieves a Python list of subtrees that represent the user
structures in the XML tree. Then we can write a for
loop that looks at each of the user nodes, and prints the name
and id
text elements as well as the x
attribute from the user
node.
User count: 2
Name Chuck
Id 001
Attribute 2
Name Brent
Id 009
Attribute 7