Skip to content

Instantly share code, notes, and snippets.

@kozo2
Last active January 4, 2016 18:29
Show Gist options
  • Save kozo2/8661110 to your computer and use it in GitHub Desktop.
Save kozo2/8661110 to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment