python lxml - modify attributes
You could try this:
r = etree.fromstring('...')element = r.find('//avp[@name="Host-IP-Address"]')# Access valueprint 'Current value is:', element.get('value')# change valueelement.set('value', 'newvalue')
Also, note that in your example you're using the text()
method, but that's not what you want: the "text" of an element is what is enclosed by the element. For example, given this:
<someelement>this is the text</someelement>
The value of the text()
method on the <somevalue>
element is "this is the text".