RSK
RSK

Reputation: 17516

How to update xml file using lxml and python?

<example>
    <login>
        <id>1</id>
        <username>kites</username>
        <password>kites</password>
    </login>
</example>

How can i update password using lxml? and now can i add one more record to the same file?

please provide me a sample code

Upvotes: 4

Views: 3546

Answers (1)

Svetlozar Angelov
Svetlozar Angelov

Reputation: 21660

example = etree.Element("example")
login = etree.SubElement(example, "login")
password = etree.SubElement(login,"password")
password.text = "newPassword"

This is a good tutorial

Upvotes: 4

Related Questions