I am new to Groovy and I am trying to parse both a valid rest resource and an invalid one. For example:
this code works fine -
def entity = new XmlSlurper().parse('http://api.twitter.com/1/users/show/slashdot.xml')
println entity.name()
println entity.screen_name.text()
when I run it, I get output:
user
slashdot
but when I pass an invalid url to xmlSlurper, like this
def entity = new XmlSlurper().parse('http://api.twitter.com/1/users/show/slashdotabc.xml')
println entity.name()
println entity.screen_name.text(
)
I get this error message:
Caught: java.io.FileNotFoundException: http://api.twitter.com/1/users/show/slashdotabc.xml
at xmltest.run(xmltest.groovy:1)
Although the url returns an hash code (like below) with an error message which I would like to parse and display it.
<hash>
<request>/1/users/show/slashdotabc.xml</request>
<error>Not found</error>
</hash>
How can I parse a url which returns a 404 but with error information?
Any help will be appreciated.
-- Thanks & Regards, Frank Covert