Skip to content

Instantly share code, notes, and snippets.

@trishagee
Created October 1, 2014 01:25
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 trishagee/cd3d1f5f2132e0b62b57 to your computer and use it in GitHub Desktop.
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.
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