Created
January 2, 2011 12:03
-
-
Save miceno/762472 to your computer and use it in GitHub Desktop.
Read an XML from an URL
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 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