Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SAXException

 
Kutts Kutts
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginner in SAX. I am able to get the error message on the vent of an exception (error or warning). But I want to get the element which caused it. How can that be done?. eg: The error msg shown now is like " Attribute "RollNumber" is required and must be specified for element
"StudentDetails". in entity file:///D:/abc/def/classes/abc.xml"

What I want is a method by which I get the element name only ie StudentDetails and the value which is wrong(in case it is a Data Value error).


 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to javaranch, please change your display name according to the http://www.javaranch.com/name.jsp policy.
----------
From the error message, it implies to me that your parser has the schema validation turned on.
Please chekc whether your xml is valid to your xmlschema first.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want the element that caused the parsing exception, I see two options:
1) Use SAXParseException#getLineNumber() and SAXParseException#getColumnNumber() to find out the location of the error and seek out that particular point in the XML file
2) In your handler class, keep count of which element you're "in" at any one time. Then, when you get an exception from parse(), ask the handler object for the name of the last element it entered successfully.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic