The link below gives us the list of ingredients in recipelist. I would like to extract the names of the ingredient and save it to another file using python. http://stream.massey.ac.nz/file.php/6087/Eva_Material/Tutorials/recipebook.xml
So far I have tried using the following code, but it gives me the complete recipe not the names of the ingredients:
from xml.sax.handler import ContentHandler
import xml.sax
import sys
def recipeBook():
path = "C:\Users\user\Desktop"
basename = "recipebook.xml"
filename = path+"\\"+basename
file=open(filename,"rt")
# find contents
contents = file.read()
class textHandler(ContentHandler):
def characters(self, ch):
sys.stdout.write(ch.encode("Latin-1"))
parser = xml.sax.make_parser()
handler = textHandler( )
parser.setContentHandler(handler)
parser.parse("C:\Users\user\Desktop\\recipebook.xml")
file.close()
How do I extract the name of each ingredient and save them to another file?