我已经创建了一个twitter feed,其中每个条目都是这样的:
<entry>
<id>tag:search.twitter.com,2005:30481912300568576</id>
<published>2011-01-27T04:27:08Z</published>
<link type="text/html" rel="alternate" href="http://twitter.com/LadyCourtz/statuses/30481912300568576"/>
<title>U always right. ml</title>
<content type="html">U always right. T <a href="http://twitter.com/Star_babey">@Star_babey</a>: But its only <b>twitter</b> tho star u wilding...lml</content>
<updated>2011-01-27T04:27:08Z</updated>
<link type="image/png" rel="image" href="http://a2.twimg.com/profile_images/1221429153/248287865_normal.jpg"/>等等等等
我在grails/GSP中需要做的是显示像<img src=${tweet.imgUrl}/>这样的图像,所以这看起来是一个很好的元编程XML结果的例子,但是作为Groovy nooby我遇到了麻烦。
看看为什么至少有2个“链接”节点,图像url有一个rel="image"属性。所以我试过..。
def records = new XmlSlurper().parse(response.data)
records.entry.metaClass.imgUrl = { -> return delegate.link?.find{it?.@rel == 'image'}?.@href }但是像这样的错误我无法超越:
groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.NodeChild.shout() is applicable for argument types: () values: []感谢您的任何帮助
发布于 2011-01-28 18:26:40
不需要元编程我不认为,你应该能够做到:
imageUrlList = new XmlSlurper().parse( response.data ).entry.link.findAll { it.@rel == 'image' }*.@href然后,您应该会得到每个位置的字符串列表...
你要把整个XmlSlurper传回GSP吗?我可能只提取您需要的数据,然后只发送回来
https://stackoverflow.com/questions/4825152
复制相似问题