Are you sure node.data contains newlines? You could try just: print node.data print node.data.split('\n') This should give you an idea. From the interpreter: >>> s = """ ... abc ... def ... xyz""" >>> s.split('\n') ['', 'abc', 'def', 'xyz']