Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

update value in xml python

import xml.etree.ElementTree as ET
filename = "example.xml"
xmlTree = ET.parse(filename)
rootElement = xmlTree.getroot()
for element in rootElement.findall("book"):
    #Find the book that has title as 'Python Tutorial'
    if element.find('title').text == 'Python Tutorial' :
        #Change the price
        element.find('price').text = "50.00"
#Write the modified xml file.        
xmlTree.write(filename,encoding='UTF-8',xml_declaration=True)
Source by techeplanet.com #
 
PREVIOUS NEXT
Tagged: #update #xml #python
ADD COMMENT
Topic
Name
9+7 =