Last active
August 29, 2015 14:06
-
-
Save geraldstanje/4a317489448f080f7a36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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