This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Daniel.Valencia
almost 9 years

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?