<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 XML Processing
Here are the contents of the input/menu.xml
xml
&lt;breakfast_menu&gt;
    &lt;food name="Belgian Waffles"&gt;
        &lt;price&gt;$5.95&lt;/price&gt;
        &lt;description&gt;two of our famous Belgian Waffles with plenty of real maple syrup&lt;/description
        &lt;calories&gt;650&lt;/calories&gt;
    &lt;/food&gt;
    &lt;food name="Strawberry Belgian Waffles"&gt;
        &lt;price&gt;$7.95&lt;/price&gt;
        &lt;description&gt;light Belgian waffles covered with strawberries and whipped cream&lt;/description&gt;
        &lt;calories&gt;900&lt;/calories&gt;
    &lt;/food&gt;
    &lt;food name="Berry-Berry Belgian Waffles"&gt;
        &lt;price&gt;$8.95&lt;/price&gt;
        &lt;description&gt;light Belgian waffles covered with an assortment of fresh berries and whipped cream&lt;/description&gt;
        &lt;calories&gt;900&lt;/calories&gt;
    &lt;/food&gt;
    &lt;food name="French Toast"&gt;
        &lt;price&gt;$4.50&lt;/price&gt;
        &lt;description&gt;thick slices made from our homemade sourdough bread&lt;/description&gt;
        &lt;calories&gt;600&lt;/calories&gt;
    &lt;/food&gt;
    &lt;food name="Homestyle Breakfast"&gt;
        &lt;price&gt;$6.95&lt;/price&gt;
        &lt;description&gt;two eggs, bacon or sausage, toast, and our ever-popular hash browns&lt;/description&gt;
        &lt;calories&gt;950&lt;/calories&gt;
    &lt;/food&gt;
&lt;/breakfast_menu&gt;
Use ElementTree
Step1:  Use xmltodict
xmltodict is another simple library that aims at making XML feel like working with JSON.
Step2:  Use untangle
untangle is a simple library which takes an XML document and returns a Python object which mirrors the nodes and attributes in its structure
<ASSISTANT_TASK:>
Python Code:
# import the appropriate libraries
import xml.etree.ElementTree as ET # xml processing
# read the XML file
tree = ET.parse('input/menu.xml')
print('tree element:\t', tree)
# get the root of the tree
root = tree.getroot()
print 'root element:\t ', root
# here is the name of the root element
root.tag
# get the children of breakfast_menu, the next level down the tree
children = root.getchildren()
for child in children:
    print (child.tag)
# for each child (node), get it's children and print out their names (tags)
for child in children:
    grand_children = child.getchildren()
    print (child.tag, '\t', child.attrib)
    for grand_child in grand_children:
        print (grand_child.tag)
# make a list of all the <food> tags
food_tags = root.findall('food')
print ('number of food tags = ', len(food_tags))
# print the <food> tags - it's not what you would expect
print (food_tags)
# access the enties in the list
first_food_item = food_tags[0]
print ('the first child node is:\t', first_food_item)
# here's how we can view a child node's content
ET.dump(first_food_item)
section = 'food'
tag = 'price'
node = root.find(section)
subnode = node.find(tag)
print ("Path to Price subnode of Food node:")
print ("Root:", str(root), " Node: ", node, "Subnode: ", subnode)
#node = root.find('food')
#subnode = node.find('prince')
#subsubnode = subnode.find('curr')
#Specify the path to the 'name' attribute of the 'food' node
node = root.find(section)
attribute = node.attrib['name']
print ("Path to Name attribute of Food node:")
print ("Root:", str(root), " Node: ", node, "Attribute: ", attribute)
#Find the attributes of each food node
print "All nodes, subnodes and attributes:" 
for node in root:
    print (node.tag, node.attrib)
    for subnode in node:
        print (subnode.tag, subnode.text)
 #Add a new attribute to each food tag   
for node in tree.iter(tag='food'):
    node.set('category', 'breakfast')
# you can search by name
name = 'Belgian Waffles'
for selected_name in root.findall("./food/[@name='%s']" % name):
     #print the description associated with the selected name
    print "Found Belgian Waffles!"
    print name, ":",  selected_name.find('description').text
#find a specific node
#and update a subnode
for node in tree.iter(tag='food'):
    if node.attrib['name'] == 'French Toast':
        subnode = node.find('price')
        print ("Subnode text: ", subnode.text)
        subnode.text = '$6.50'
        print ("Modified subnode text: ",  subnode.text)
#Add a new subelement to the root                                                                        
new_name = 'Three-Egg Omlette'  
new_price = '$7.95'
new_description = 'three-egg omlette with your choice of meat, cheese and vegetables'
new_calories = '900'                                
food_node = ET.SubElement(root, 'food', {'name':new_name})
price_subnode = ET.SubElement(food_node, 'price')
price_subnode.text = new_price
description_subnode = ET.SubElement(food_node, 'description')
description_subnode.text = new_description
calories_subnode = ET.SubElement(food_node, 'calories')
calories_subnode.text = new_calories
#<el name='x'> 4 </el>
#<price amount='5.5' cur='$$'/>
#Write out the modified xml     
tree.write('output/outputMenu.xml') 
Explanation: XML Processing
Here are the contents of the input/menu.xml
xml
&lt;breakfast_menu&gt;
    &lt;food name="Belgian Waffles"&gt;
        &lt;price&gt;$5.95&lt;/price&gt;
        &lt;description&gt;two of our famous Belgian Waffles with plenty of real maple syrup&lt;/description
        &lt;calories&gt;650&lt;/calories&gt;
    &lt;/food&gt;
    &lt;food name="Strawberry Belgian Waffles"&gt;
        &lt;price&gt;$7.95&lt;/price&gt;
        &lt;description&gt;light Belgian waffles covered with strawberries and whipped cream&lt;/description&gt;
        &lt;calories&gt;900&lt;/calories&gt;
    &lt;/food&gt;
    &lt;food name="Berry-Berry Belgian Waffles"&gt;
        &lt;price&gt;$8.95&lt;/price&gt;
        &lt;description&gt;light Belgian waffles covered with an assortment of fresh berries and whipped cream&lt;/description&gt;
        &lt;calories&gt;900&lt;/calories&gt;
    &lt;/food&gt;
    &lt;food name="French Toast"&gt;
        &lt;price&gt;$4.50&lt;/price&gt;
        &lt;description&gt;thick slices made from our homemade sourdough bread&lt;/description&gt;
        &lt;calories&gt;600&lt;/calories&gt;
    &lt;/food&gt;
    &lt;food name="Homestyle Breakfast"&gt;
        &lt;price&gt;$6.95&lt;/price&gt;
        &lt;description&gt;two eggs, bacon or sausage, toast, and our ever-popular hash browns&lt;/description&gt;
        &lt;calories&gt;950&lt;/calories&gt;
    &lt;/food&gt;
&lt;/breakfast_menu&gt;
Use ElementTree
End of explanation
import xmltodict
with open('input/menu.xml') as fd:
    doc = xmltodict.parse(fd.read())
print(doc)
Explanation: Use xmltodict
xmltodict is another simple library that aims at making XML feel like working with JSON.
End of explanation
import untangle
obj = untangle.parse('input/menu.xml')
obj.breakfast_menu.food[0].calories
Explanation: Use untangle
untangle is a simple library which takes an XML document and returns a Python object which mirrors the nodes and attributes in its structure
End of explanation
<END_TASK>