• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

SAXException while parsing a well formed XML

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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?
 
Priya Lavti
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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?
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic