Maybe a more robust approach is just to walk through the string counting the (increments) of the number of brackets "<" and ">" as you know that all the relevant text occurs right after a ">" has occured that sets your counter to 0 (meaning you're at the "highest level"). There's no relevant text if the next character is again a "<".
-- http://mail.python.org/mailman/listinfo/python-list