Lots of python XML parsing tutorials out there, but not that many on updating XML, and none I can find that match my needs. Sorry for the N00B.
I have a need to add subelements to a particular element based on the value of another subelement.
<CadData>
<FireIncidentCollection>
<FireIncident>
<IncidentNo>12345</IncidentNo>
<ApparatusCollection>
<Apparatus>
<Unit>E29</Unit>
</Apparatus>
<Apparatus>
<Unit>TW29</Unit>
</Apparatus>
<Apparatus>
<Unit>R29</Unit>
</Apparatus>
</ApparatusCollection>
</FireIncident>
</FireIncidentCollection>
</CadData>
I have values and even other subtrees I need to add based on the "Unit" value of an "Apparatus" element. For example, I may need to add this snippet in that "Apparatus" element when the "Unit"=="TW29":
<DispatchTime>20221115T06:05:04-6.00</DispatchTime>
<ApparatusPersonnelCollection>
<ApparatusPersonnel>
<ID>23456</ID>
</ApparatusPersonnel>
<ApparatusPersonnel>
<ID>78901</ID>
</ApparatusPersonnelCollection>
So far I'm resisting the urge to dump everything to a DB and re-writing the whole file each time :). I'm sure there's a way in ElementTree or DOM, but I can't figure it out (not for lack of effort). Any pointers are greatly appreciated. Thanks!
(Oh, and no, I don't control the schema- I just have to adhere to it).