Replace value of node using getElementsByTagName

Stefan Behnel stefan_ml at behnel.de
Sun Aug 10 09:01:20 EDT 2008


Ouray Viney wrote:
> Is there an easy way to replace the node value of <ib>?  Perhaps I am
> trying to use the wrong python XML library?

Looks like it. Try ElementTree.

    from xml.etree import ElementTree
    tree = ElementTree.parse("yourfile.xml")
    for ib in tree.findall("//ib"):
        ib.text = calculate_new_value(ib.text)

Stefan



More information about the Python-list mailing list