Is it possible to get the line number(s) and file name where an element
was parsed, assuming it was parsed from a file?
Joel VanderWerf vjoel@PATH.Berkeley.EDU wrote in message news:3EED0578.3060109@path.berkeley.edu…
Is it possible to get the line number(s) and file name where an element
was parsed, assuming it was parsed from a file?
Not currently, although that’s a good idea. I’ll stick it in the
feature request list.
With the REXML 2.7 branch (or Ruby CVS), you can get the line numbers.
Here’s an example:
source = REXML::IOSource.new( File.new( “documentat.xml” ))
REXML::Document.new(s) # Parse the document
bytes, line_sep_lines, lines = s.current_line
‘bytes’, in this particular case, should be equal to the size of the
file, in bytes. ‘nodes’ is, effectively, equal to the number of ‘>’
characters there are in the XML document; it probably won’t be of much
use to you, as it pertains to how REXML internally parses streams.
‘lines’ is the actual number of CR/LF lines there are in the document.
If you combine this information with the SAX or Pull parsers, you
should be able to extrapolate the line number of a particular parse
event. It isn’t much help in the case of a tree parser, I’m afraid.
— SER