wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes SAXException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "SAXException" Watch "SAXException" New topic
Author

SAXException

Kutts Kutts
Greenhorn

Joined: May 27, 2004
Posts: 1
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).




Whatever happends is always for the best :-)
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SAXException