Groovy XmlSlurper

Posted by Langali on Stack Overflow See other posts from Stack Overflow or by Langali
Published on 2010-05-09T20:31:52Z Indexed on 2010/05/09 21:18 UTC
Read the original article Hit count: 529

Filed under:
<div id="videos">
    <div id="video">
        <embedcode>....</embedcode>   
    </div>
</div>

I need to grab the video embed code, and not just the text inside a XMl tag. Any idea how can I grab the snippet of XML using XmlSlurper?

I need the whole line: <embedcode>....</embedcode>

© Stack Overflow or respective owner

Groovy XmlSlurper

Posted by Langali on Stack Overflow See other posts from Stack Overflow or by Langali
Published on 2010-05-09T00:06:33Z Indexed on 2010/05/09 0:18 UTC
Read the original article Hit count: 529

Filed under:

I am trying to parse a html file using Groovy XmlSlurper.

<div id="users">
 <h1>Name: Joe Doe</h1>
 <div id="user">
    <div id="user_summary">Game: 1</div>
    <object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/DApLO_HDhD0&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/DApLO_HDhD0&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>
 </div>
 <div id="user">
    <div id="user_summary">Game: 2</div>
   ...
 </div>
 <div id="user">
   ....
 </div>
</div>
<div id="featured_users">
  <div id="user">
   ...
 </div>
 <div id="user">
   ....
 </div>
</div>

I need to grab each user (and not featured user) with his name, summary and object tag (which the video embed code).

Anybody wanna give it a shot?

Here's a start:

def parser =new XmlSlurper(new org.ccil.cowan.tagsoup.Parser())
def response = parser.parseText(htmlString)
def users = response.depthFirst().collect { it }.findAll { it.@id == "users" }
users.each {
   ......
}

I cant seem to be able to get much further:

© Stack Overflow or respective owner

Related posts about groovy