Last active
January 4, 2016 18:29
-
-
Save kozo2/8661110 to your computer and use it in GitHub Desktop.
This file contains 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