Skip to content

Instantly share code, notes, and snippets.

@geraldstanje
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldstanje/4a317489448f080f7a36 to your computer and use it in GitHub Desktop.
Save geraldstanje/4a317489448f080f7a36 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