Skip to content

Instantly share code, notes, and snippets.

@miceno
Created January 2, 2011 12:03
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 miceno/762472 to your computer and use it in GitHub Desktop.
Save miceno/762472 to your computer and use it in GitHub Desktop.
Read an XML from an URL
import groovy.xml.DOMBuilder
import javax.xml.parsers.*
// URL to read
def url= "http://stackoverflow.com/feeds/tag?tagnames=groovy&sort=newest"
// Parse the text
def doc
// Reading with XmlSlurper
doc = new XmlSlurper().parse( url)
println "XmlSlurper doc " + doc.dump
// Reading with DOMBuilder
doc = DOMBuilder.parse( new InputStreamReader( url.toURL().openStream()))
println "DOMBuilder doc " + doc.dump()
// Reading with Java DOM
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( url);
println "DocumentBuilderFactory doc " + doc.dump()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment