Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

[groovy-user] XmlSlurper finding elements

Anders Viklund

2010-08-28

Replies: Find Java Web Hosting

Author LoginPost Reply

/*
Hi,

How can I select ALL activity elements that has a description in this
example xml?
The location should not matter, so even if its located under a/b/c/d.. etc.
it should be possible to find the element.
This should be a fairly simple task to do, but I just cannot get it working
properly.

Thanks for any help how to solve this!
*/

def xml="""
<ProcessDefinition>
  <activity>
    <name>activity name1</name>
    <description>description here</description>
  </activity>
  <activity>
    <name>dont select me because I dont have a description</name>
  </activity>
  <anyThing>
    <activity>
       <name>activity name2</name>
       <description>Some other description here</description>
    </activity>
  </anyThing>
</ProcessDefinition>
"""

def node = new XmlSlurper().parseText(xml)

def activities = node.activity.findAll{it.description!=null}

activities.each{
  println """${it.name} : ${it.description}"""
}

/*
OUTPUT:
activity name1 : description here
dont select me because I dont have a description :
*/
--
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.