• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SAXException

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).


 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic