I think that XPath is a better tool for your task than your nested looping through a three deep nested loop.
I can't tell exactly from your code logic but I am guessing that an Xpath expression like ("//function/text()") would cleanly extract all of the function node values regardless of their place in the hierarchy.
For XPath basics in Java, See How to read XML using XPath in Javastrong text