Because the XML file I'm dealing with has inconsistent subelements I'm having some difficulty finding and editing a specific subelement that doesn't appear in the series of elements until further down the file. I'm using Python's ElementTree included with Python 2.7.1.
Here's an example of the type of XML file I'm dealing with:
<?xml vin="1.0" encoding="UTF-8" standalone="yes"?>
<whatever id='Subaru' YouCanDriveMyCar='Wednesday' transmission='stick'>
<model id='Ford' year='1972'>A</model>
<model id='Chevrolet' vin="1234567890" stereo='Alpine' airconditioning='notworking'>Volt</model>
<model id='Dodge' vin="3456789012" airconditioning='working'>Durango</model>
<model id='Mercedes' vin="4567890123" airconditioning='none'>S150</model>
<model id='BMW'>M350</model>
<model id='Volkswagen' vin="5678901234" stereo='Sony'>Beetle</model>
<model id='Honda' vin="6789012345" airconditioning="blowsicecubes">Accord</model>
</whatever>
In this example, I want to locate model id='Volkswagen' and change stereo='Sony' to 'Blaupunkt'.
If I use ElementTree to search for attribute 'stereo' it errors out because 'stereo' isn't contained in the elements at the top of the file.
Any help or hints would be greatly appreciated.