问题
I have XML as below,
<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'
}
to get the values but i don't know how to get 467 West Reservoir Road and 540-459-7505
回答1:
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()
}
来源:https://stackoverflow.com/questions/43348809/xmlslurper-issue-while-parsing