I am getting SAXException while parsing even though my XML is well formed. I am using DOM parser here. It is written in the API that SAXException can be thrown for both error and warning. Is there any way to ignore the warnings coming while parsing and hence no SAXException is thrown.
One more weird behavior I am getting is that when I catch the SAXException, it executes the catch block and after that control goes to the next line from where the exception was thrown, and that line is in try block itself. I'll show this with code example:
Ideally when SAXException is thrown on line 3, control should go to the line 7 and the to line 9 after the catch block. But in current senario control is going to line 4 after line 7. It is something very strange happening. My guess is, is it because of some property of SAXException, when thrown for warning?
Any suggetion/advice in this regard will be helpful. Thanks in advance
And also the 1st line in bold is in the catch block and the last line is in the try block. That is why I am sure controling is flowing from catch block to try block.
Are you sure? Again what you are suggesting would mean that the basic, well understood and extremely well tested control mechanisms in the Java language were broken. If it were me, I would be more inclined to think I had made a mistake, rather than Java is behaving in a way it has never behaved before.
FYI - your exception is almost certainly because you have leading whitespace in your XML file, though I can't be 100% sure. I'm guessing that the code you posted is not the code you are running (I don't see the message "Exception while parsing:" anywhere in the stack trace). Could you post the real code?
subject: SAXException while parsing a well formed XML