Groovy “find” closure…Traversing through recursive xml

zonmoy

New Member
If i have my GPath like this:\[code\]<Apple> <Mango> <id>5 </id> </Mango> <Mango> <id>10 </id> </Mango></Apple>\[/code\]To get a Mango which has an id of 5, i would do,\[code\]GPathResult result = Apple.find{it.Mango.id=5}\[/code\]But If my GPath was recursive. I mean, an apple can have a mango. And a Mango can again have an apple in it. For ex:\[code\]<Apple> <Mango> <id>10</id> <Apple> <Mango> <id>5 </id> </Mango> </Apple> </Mango></Apple>\[/code\]How do I get the mango with an id of '5'. However recursive, the GPath might be(Mango with id '5' can be in any level of recursion), I need to find for mango with id of '5'. How can I achieve this with a find closure?Advance Thanks
 
Back
Top