Ross Bamford wrote:
> On Mon, 2006-05-08 at 03:21 +0900, Eli Bendersky wrote:
>> When REXML throws ParseException, a whole load information is spilled 
>> into msg. Although this is useful for debugging, it hardly is an option 
>> for a "real-life" application that just has to notify the user of an 
>> error in his .xml file in the friendliest way possible.
>> 
>> How can I get just the "malformed XML: missing tag start" part (plus the 
>> line in the file) without all the stack trace and the information that 
>> comes after it, which for some reason is repeated twice. Is this 
>> possible without deconstructing the raised msg ?
> 
> This is probably a bit naive but maybe will be a start:
> 
> begin
>   doc = REXML::Document.new File.new('bad.xml')
> rescue REXML::ParseException => ex
>   puts "Failed: #{ex.message[/^.*$/]} (#{ex.message[/Line:\s\d+/]})"
> end

Ross,

Thanks for your suggestion, it was clear to me that this is possible, 
but I seek a more 'sane' way of doing it. What if REXML changes the 
format of the message slightly in the next version - the regexes won't 
match any longer. I don't see why there can't be a short way to print a 
message that is useful to an end user.


REXML is praised as *the* XML parsing library of Ruby and is part of the 
standard library, surely someone noticed its useless error reporting ?!

-- 
Posted via http://www.ruby-forum.com/.