Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes SAXException while parsing a well formed XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "SAXException while parsing a well formed XML" Watch "SAXException while parsing a well formed XML" New topic
Author

SAXException while parsing a well formed XML

Priya Lavti
Ranch Hand

Joined: Oct 11, 2004
Posts: 41
Hi all,

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


-Priya
SCJP 5.0
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


My guess is, is it because of some property of SAXException, when thrown for warning?

If the code in your catch block is not being run then its not a SAXException that is being thrown. Could you post the stack trace you see?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Priya Lavti
Ranch Hand

Joined: Oct 11, 2004
Posts: 41
SAXException is thrown and control is also going to catch block.
But after that its returning back to try block... that is what strange here...
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

That sort of behaviour is against the core control mechanisms of Java. Are you sure this is what is happening, and if so how are you sure?

Also, could you post the stack trace you see? Its is much easier to talk about an Exception when we can see the message you see.
Priya Lavti
Ranch Hand

Joined: Oct 11, 2004
Posts: 41
yes I am sure, coz I was actually having System.out.println (SOP) in both the place, catch block and try block. And 1st it is pritning the SOP of catch followed by of the try block.



Here I have caught the SAXException at TransmitManager in a catch block and then throwing my user defined exception and catching that into the jsp file.

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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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?
 
Consider Paul's rocket mass heater.
 
subject: SAXException while parsing a well formed XML