Skip to content

Instantly share code, notes, and snippets.

View alexkli's full-sized avatar

Alexander Klimetschek alexkli

View GitHub Profile
@alexkli
alexkli / README.md
Last active December 15, 2015 17:29
Line number support for REXML documents parsed from files

Line number support for REXML documents

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.