解析时XmlSlurper问题 [英] XmlSlurper Issue while Parsing
本文介绍了解析时XmlSlurper问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的XML如下,
<div class="storeContainer">
<div class="storeCount">50</div>
<div class="mapAddress" id="store50">
<h4 onclick="changeMap(50,38.872432,-78.530463);">Woodstock, VA</h4>
<h5>Woodstock Square</h5>467 West Reservoir Road
<br/>540-459-7505
<br/>
<a href="https://maps.google.com/maps?saddr=geo&daddr=467+West+Reservoir+Road+Woodstock+VA+22664&sll=38.872432,-78.530463&sspn=0.011265,0.014098&z=12"
class="getDirections">Get Directions</a>
</div>
</div>
</div>
我想阅读地址详细信息,并且正在使用
I wanted to read address details and am using the
def envelope = new XmlSlurper().parseText(response.toString());
envelope.'**'
.each {
println it.h4.text()
println it.h5.text()
println it.a.@'href'
}
获取值,但我不知道如何获取水库西路467号和 540-459-7505
to get the values but i don't know how to get 467 West Reservoir Road and 540-459-7505
推荐答案
如果切换到XmlParser
,则可以执行以下操作:
If you switch to XmlParser
, you can do:
def envelope = new XmlParser().parseText(xml);
envelope.'**'.find { it.@class == 'mapAddress' }.with { node ->
println h4.text()
println h5.text()
println a.@'href'
println node.children().findAll { it.getClass() == String }*.trim()
}
这篇关于解析时XmlSlurper问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文