Added code to send events for each element seen rather than build up the document tree