How to update the text of a tag in XML using Elementree

Posted by Christopher on Stack Overflow See other posts from Stack Overflow or by Christopher
Published on 2010-06-10T21:41:39Z Indexed on 2010/06/10 22:13 UTC
Read the original article Hit count: 599

Filed under:

Using elementree, the easiest way to read the text of a tag is to do the following:

import elementtree.ElementTree as ET
sKeyMap = ET.parse("KeyMaps/KeyMap_Checklist.xml")
host = sKeyMap.findtext("/BrowserInformation/BrowserSetup/host")

Now I want to update the text in the same file, hopefully without having to re-write it with something easy like:

host = "4444"
sKeyMap.replacetext("/BrowserInformation/BrowserSetup/host")

Any ideas?

Thx in advance Christopher

© Stack Overflow or respective owner

Related posts about python