db.mytable.insert(**record_dictionary)
All of the effort will be in parsing the XML, so you should check the documentation of the various XML libraries and ask questions in their forums (or on Stack Overflow). The details will depend on the structure of your XML. Ultimately, you want to loop over the records in the XML, and for each record, build a dictionary where the keys are the DAL table field names and the values are the record values you want to insert. Once you have such a dictionary, the DAL insert for a single record is simple:
db.mytable.insert(**record_dictionary)
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/ccWa_xekecQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for reply.Could you please give me one example and where I can get enough matter to write the code.
Thanks for reply.Could you please give me one example and where I can get enough matter to write the code.
f = codecs.open("path/
myfilename",
encoding="ISO8859-1", mode="r")
soup = BeautifulSoup(f)
for x in soup.find_all("td", class_="element-title"):
if not x.contents[0]:
print "blowing up on %s" % x.name
while not isinstance(x.contents[0], NavigableString):
x = x.contents[0]
doc = xml.dom.minidom.parse("...my_xml.xml")// Here you parse the xml file
for node in doc.getElementsByTagName("recipe")://Here you read in a cycle the tags which contain numerous attributes each
t=node.getAttribute("name")//Each attribute is stored as a string in a variable that you can add to the db
d=node.getAttribute("creator")
try:
db.Recipe.update_or_insert(Name=t,Creator=d)//each time you cycle through each node you are adding the name and creator to the db if both aren't already there
except:
pass