XML and Java easy task - infinite loop detection