Created
October 1, 2014 01:25
-
-
Save trishagee/cd3d1f5f2132e0b62b57 to your computer and use it in GitHub Desktop.
Shows the section of the script that deals with transforming the XML into something MongoDB-shaped.
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
def xmlSlurper = new XmlSlurper().parse(new File('resources/all-coffee-shops.xml')) | |
xmlSlurper.node.each { child -> | |
Map coffeeShop = ['openStreetMapId': child.@id.text(), | |
'location' : ['coordinates': [Double.valueOf(child.@lon.text()), Double.valueOf(child.@lat.text())], | |
'type' : 'Point']] | |
child.tag.each { theNode -> | |
def fieldName = theNode.@k.text() | |
if (isValidFieldName(fieldName)){ | |
coffeeShop.put(fieldName, theNode.@v.text()) | |
} | |
} | |
if (coffeeShop.name != null) { | |
println coffeeShop | |
collection.insert(new BasicDBObject(coffeeShop)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment