parsing of xml to mysql database

H.Genedy

New Member
In my app,i am including a function called xml parsing.I am trying to data the data from an xml file and save it to mysql database.I coded this with the help from google engine,but as required the data's are not saving in the database.I can run the app without any error.Please see my codes belowviews.py\[code\]def goodsdetails(request): path = "{0}shop.xml".format(settings.PROJECT_ROOT) xmlDoc = open(path, 'r') xmlDocData = http://stackoverflow.com/questions/15826948/xmlDoc.read() xmlDocTree = etree.XML(xmlDocData) for items in xmlDocTree.iter('item'): item_id = items[0].text customername = items[1].text itemname = items[2].text location = items[3].text rate = items[4].text shop=Shop.objects.create(item_id=item_id,customername=customername, itemname=itemname,location=location,rate=rate) shop.save()shops = Shop.objects.all() context={'shops':shops} return render(request,'index.html', context)\[/code\]I am using the above logic to save the data in database from xml file.I am not getting any error but it is not saving into databaseExpected answers are most welcome.*Update:*I updated the code,really the xml data gets saved in db,but while displaying the same i am getting the following Traceback\[code\]IntegrityError at /(1062, "Duplicate entry '101' for key 'PRIMARY'")\[/code\]Thanks
 
Back
Top