tags:

views:

78

answers:

1
+1  Q: 

Groovy XmlSlurper

<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>

+1  A: 

This can be done by using XMLParser instead of XMLSlurper, and XMLNodePrinter:

def xml = """
<div id="videos">
    <div id="video">
        <embedcode><i>codeA</i>CodeB</embedcode>   
    </div>
</div>"""

def parser = new XmlParser().parseText(xml)
new XmlNodePrinter().print(parser.div.embedcode[0])
Michael Borgwardt