Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3 as db
- import json
- con = db.connect('sis_dis.db')
- cur = con.cursor()
- def selectAlumno(rut, tipo = "json"):
- cur.execute("SELECT * FROM alumnos WHERE rut= '%s'" % rut)
- info = cur.fetchone()
- if tipo == "json":
- msg = {"rut":info[0],"nombre":info[1],"apellido":info[2],"email":info[3]}
- return json.dumps(msg, sort_keys=False, indent=4)
- elif tipo == "xml":
- from xml.dom.minidom import Document
- # Create the minidom document
- doc = Document()
- # Create the <wml> base element
- wml = doc.createElement("usuario")
- wml.setAttribute("id", info[0])
- doc.appendChild(wml)
- # Create the main <card> element
- rut = doc.createElement("rut")
- wml.appendChild(rut)
- nombre = doc.createElement("nombre")
- wml.appendChild(nombre)
- apellido = doc.createElement("apellido")
- wml.appendChild(apellido)
- email = doc.createElement("email")
- wml.appendChild(email)
- # Give the <p> elemenet some text
- ptext = doc.createTextNode(info[0])
- rut.appendChild(ptext)
- # Give the <p> elemenet some text
- ptext = doc.createTextNode(info[1])
- nombre.appendChild(ptext)
- # Give the <p> elemenet some text
- ptext = doc.createTextNode(info[2])
- apellido.appendChild(ptext)
- # Give the <p> elemenet some text
- ptext = doc.createTextNode(info[3])
- email.appendChild(ptext)
- # Print our newly created XML
- return doc.toprettyxml(indent=" ")
Advertisement
Add Comment
Please, Sign In to add comment