Getting parent node attribute values from XML files
Posted on 2006-06-30
I have an XML file:
<garage name="wood road">
<vehicle make="toyota" model="yaris">
New model - 1 litre Terra
<vehicle make="nissan" model="note">
Second hand - red, 15000 miles
<garage name="john street">
<vehicle make="ford" model="mondeo">
New car - black, air-con fitted
<vehicle make="mazda" model="323">
Second hand - silver, 35000 miles
I need to first of all find the makes of all the vehicles. This I can do using:
vehicleLst = xmldoc.getElementsByTagName("vehicle")
vehicleMake = 
for vehicle in vehicleLst:
For each of the makes in this list, I then need to find the name of the garage where these vehicles are housed.
I've been trying to use parentNode for this, but to no avail.
If I could have the vehicle makes and the corresponding garages together in a list (within a list) or a dictionary, it would be great.