XML into MongoDB - quick and dirty
Import XML from various API’s to MongoDB.
import net.liftweb.json.Xml // converts XML to JSON import com.mongodb.casbah.Imports._ // To put stuff in Mongo import com.mongodb.casbah.MongoDB // To connect to Mongo import com.mongodb.util.JSON // To parse JSON into a MongoDBObject import net.liftweb.json._ // To output Lift JSON as actual JSON import scala.xml.XML // To load XML // load the XML val xml = XML.load("http://www.w3schools.com/xml/note.xml") // fire up mongo connection val con = MongoConnection() val col = con("test")("xmlTest") // convert the XML into a BasicDBObject val bdo:BasicDBObject = JSON.parse(pretty(render(Xml.toJson(xml)))).asInstanceOf[BasicDBObject] // and insert it col.insert(bdo) // check that it's there: col.find.foreach(println)










