The Ruby REXML library unfortunately has no built-in support to retrieve line numbers of elements when using Documents (DOM).
This little extension fixes this and gives you Element.start_line
("<" location) and Element.end_line
("/>" location), also for other XML items such as Entities, Decl, etc., just not individual attributes.
Use with doc = XML::parse_xml(file)
as replacement for the usual doc = REXML::Document.new(file)
.
Update: this change makes parsing of certain xml files fail, due to a broken REXML::IOSource#current_line implementation that resets the stream to the wrong location.