I have a plist i have parsed with lxml. Thanks to help from users here I have a full set of items i want to add, in the correct format, and can add them in. The trouble I have now is using 2 different levels of the xml file to select where to put it. If I have the following how can i be sure to insert my text over "WUT" in the set that uses both "Notes" and "13", and not in "Books" and "13"? Or the other way around?
<root>
<key>Title</key>
<dict>
<key>Set</key>
<dict>
<key>Notes</key>
<dict>
<key>Tester</key>
<array>
<dict>
<key>13</key>
<dict>
<key>Param</key>
<array>
<string>WUT</string>
</array>
</dict>
<key>18</key>
<dict>
<key>Param</key>
<array>
<string>WUT</string>
</array>
</dict>
</dict>
</array>
</dict>
</dict>
<dict>
<key>Books</key>
<dict>
<key>Tester</key>
<array>
<dict>
<key>13</key>
<dict>
<key>Param</key>
<array>
<string>WUT</string>
</array>
</dict>
</dict>
</array>
</dict>
</dict>
</dict>
</root>
So ideally my new plist would look like:
<root>
<key>Title</key>
<dict>
<key>Set</key>
<dict>
<key>Notes</key>
<dict>
<key>Tester</key>
<array>
<dict>
<key>13</key>
<dict>
<key>Param</key>
<array>
<string>1</string>
<string>2</string>
<string>3</string>
<string>4</string>
<string>5</string>
</array>
</dict>
<key>18</key>
<dict>
<key>Param</key>
<array>
<string>WUT</string>
</array>
</dict>
</dict>
</array>
</dict>
</dict>
<dict>
<key>Books</key>
<dict>
<key>Tester</key>
<array>
<dict>
<key>13</key>
<dict>
<key>Param</key>
<array>
<string>WUT</string>
</array>
</dict>
</dict>
</array>
</dict>
</dict>
</dict>
</root>
I have tried using xpath and running.
for plist_title in tree.xpath('//dict[key="Notes"][1]')
for plist_tester in plist_title.xpath('//dict[key="13"][1]')
plist_tester.insert(1,myData)
but the data only gets inserted after the last "13" and not the one I would like to define it to.