inside of _parseXMLElements(). You're not keeping track of the object returned by your recursive call. Whatever gets returned by the called instance of _parseXMLElements() is disappearing as soon as the runtime returns control to the calling instance.
That way whatever is returned by _parseXMLElements() will be passed back up the stack. You should make sure that something is always passed up the recursive stack.
Check out the below example I just whipped up. Recursion is always tricky. Good luck!
P.S. I feel like every time I build something recursive I have to invent the wheel all over again. There are lots of ways to skin a recursive cat.
P.P.S. It's often best to avoid recursion all together. If you can avoid it you should, even if the end result isn't as elegant as it could be.
--This is a ridiculous example of using recursion to find
--the first word that starts with f in a string.
--No one in their right mind would solve this problem this way.
--It is written as an example only.
set theString to "Zaphod is a really amazingly cool frood."
--this is a semaphore for the recursion. If keepGoing is true then keep going.
property keepGoing : true
set theResult to findFirstWordStartingWithF(words of theString)
--Check to make sure theResult is valid
if theResult = -1 then
error "ack, no words starting with f were found"
else
--do stuff with theResult
return theResult
end if
on findFirstWordStartingWithF(wordList)
--Make sure the wordList is not empty
if length of wordList > 0 then
set currentWord to item 1 of wordList
if currentWord starts with "f" then
set keepGoing to false
return currentWord
end if
repeat while keepGoing
set newWordList to rest of wordList
--We make sure to return the result of the recursive call
--This way the result gets passed up the stack
return findFirstWordStartingWithF(newWordList)
end repeat
else
--The list is empty. It has no words.
--Return a value that is not valid in the context
return -1
end if
end findFirstWordStartingWithF