简体   繁体   中英

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

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

This is a good tutorial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM