1

here is my xml:

<request><table attributeA="50" attributeB="1"></table>........</request>

how do I update attributeA's value, to have something like attributeA="456"

<request><table attributeA="456" attributeB="1"></table>........</request>

1 Answer 1

2

Use etree and xpath :

>>> from lxml import etree
>>> xml = '<request><table attributeA="50" attributeB="1"></table></request>'
>>> root = etree.fromstring(xml)
>>> for el in root.xpath("//table[@attributeA]"):
...     el.attrib['attributeA'] = "456"
...
>>> print etree.tostring(root)
<request><table attributeA="456" attributeB="1"/></request>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.