tenderlove/nokogiri — Issue #579: Enhance SyntaxError messages for missing closing tags
Author: rbreu
Created: 2011-12-02 12:06:47+00:00
State: open

(Using Nokogiri 1.5.0)

Given the following document with an unclosed 'bar' tag

doc = Nokogiri::XML.parse("<root><foo><bar>sdfsdf</foo></root>")

I'd like to find out which of the tags is missing a closing tag since I want to be a bit smarter about where to close the tag for my usecase. At the moment I'm working with Nokogiri's error messages; in this case I get:

<Nokogiri::XML::SyntaxError: Opening and ending tag mismatch: bar line 1 and foo>
<Nokogiri::XML::SyntaxError: Opening and ending tag mismatch: foo line 1 and root>
<Nokogiri::XML::SyntaxError: Premature end of data in tag root line 1>

My problem is that the second error message makes it look like there's something wrong with the 'foo' tag. Would it be possible to enhance the error messages? Especially since the first error message isn't giving me a line number for the 'foo' tag, so in a longer document I have no way of knowing that those two 'foo's in the error messages are the same for trying to sort out myself which of the tags isn't closed.