Only thing i do not understand is that it returns from
From that snippet, I have no idea why, either, since there isn't sufficient code shown.
if ( currentLine.endsWith("<name>")) {
None of your example lines ENDED with . One of them STARTS with and one ends with </name>.