This forum is now read-only. Please use our new forums at discuss.codecademy.com.

How to use APIs with Python Forum

View Course » View Exercise

423 points
B0ff3a414d2c3cdc68622a9e6f62d44f?s=140&d=retro
Submitted by
Daniel.Valencia
over 2 years ago

Get value of multiple tags?

Sorry if my question is vague, I don't really know how to word it. Anyway, in the "Parsing XML" section, I understand (sort of) how we obtain the names from the xml file. How would we go about getting both the species and the names in the same loop?

For example, in that exercise, we have the XML file as follows:
<pets>
<pet>
<name>Jeffrey</name>
<species>Giraffe</species>
</pet>
<pet>
<name>Gustav</name>
<species>Dog</species>
</pet>
<pet>
<name>Gregory</name>
<species>Duck</species>
</pet>
</pets>

To get both, instead of getting the elements by tag name "name", would we get the elements by tag name "pet"? How then would we obtain the values in the "name" and "species" tags?