1

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&amp;daddr=467+West+Reservoir+Road+Woodstock+VA+22664&amp;sll=38.872432,-78.530463&amp;sspn=0.011265,0.014098&amp;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

tim_yates
  • 167,322
  • 27
  • 342
  • 338
prostý člověk
  • 909
  • 11
  • 29

1 Answers1

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()
}
tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • Thank you very much Tim! :-) – prostý člověk Apr 12 '17 at 08:10
  • @ThangavelLoganathan, if that has helped you need to [accept it as answer](http://stackoverflow.com/help/someone-answers) – Rao Apr 12 '17 at 08:22
  • Tim - actually i get more than 50 storecontainer div tag means i get more than 50 mapaddress div's. i want to iterate one by one. i used each method but no luck since am newbie to this. I can able to get value "node.children().findAll { it.getClass() == String }*.trim()" using the line. I want separate 467 West Reservoir Road and 540-459-7505 using some split operations in next line. Could you please me on this. it would be great! Thanks in advance. – prostý člověk Apr 12 '17 at 08:52
  • What you get is a list of values. You can iterate thru them. – Rao Apr 12 '17 at 13:32