Hello,

Out of curiosity, is there a more compact way to check if an element exists, edit if it does, insert if it doesn't ?

#=========== Edit/insert top-most name
r = root.find('./Document/name')
#if et.iselement(r)
if r is not None:
    print("Name exists: ",r.text)
    r.text = BASENAME
else:
    print("Name does not exist")
    #insert new element
    et.SubElement('/kml/Document', "name").text = BASENAME

Thank you.

_______________________________________________
lxml - The Python XML Toolkit mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/lxml.python.org/
Member address: [email protected]

Reply via email to