My XML structure is like the following:
<Root>
<App>
<Name>Monitoring1</Name>
<Status>error</Status>
<Date>2019-06-03</Date>
<Information>Error</Information>
</App>
</Root>
I have a function "def writelog(a, b)", which creates a new entry on the App level, e. g. "Monitoring2".
So, when an item on the Name level already exists, I want to update the values.
Old:
<Root>
<App>
<Name>Monitoring1</Name>
<Status>ERROR</Status>
<Date>2019-06-03</Date>
<Information>Error</Information>
</App>
</Root>
After calling the function, which will update Monitoring1:
<Root>
<App>
<Name>Monitoring1</Name>
<Status>SUCCESS</Status>
<Date>2019-06-03</Date>
<Information>Success</Information>
</App>
</Root>
How can I achieve that?
Edit:
I tried something like:
for elem in root.getiterator():
try:
elem.text = elem.text.replace('FEATURE NAME', 'THIS WORKED')
elem.text = elem.text.replace('FEATURE NUMBER', '12345')
except AttributeError:
pass
from How to search and replace text in an XML file using Python?
or
tree.find('idinfo/timeperd/timeinfo/rngdates/begdate').text = '1/1/2011'
tree.find('idinfo/timeperd/timeinfo/rngdates/enddate').text = '1/1/2011'
from: Find and Replace Values in XML using Python
But I am completly lost at the moment