Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to get details of Parse Failure in Jdom?

Posted on 2002-05-02
3
Medium Priority
?
170 Views
Last Modified: 2010-03-31
I'm using a JDOM SaxBuilder object to enforce schema validation on documents which are posted to my servlets and it works very well. However, is there a way of getting details about the element or attribute which is causing the validation to fail? At the moment I get a message like "Datatype error: Value ' ' must be one of [Y, N]" but what I'd really like to know is which attribute out of the many in my document has caused the problem.

Regards

Dave
0
Comment
Question by:howesd
  • 2
3 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 6985897
I think that you can solve this problem by setting your own org.xml.sax.ErrorHandler
0
 
LVL 1

Author Comment

by:howesd
ID: 6985924
I've done that - here's a copy of it - it's just a copy of one that I got from the net at the moment. I can't find anything within the SaxParseException class which tells me what the attribute causing the problem is. Line number of always 2 as I just get the XML posted to me.

Dave

import org.jdom.input.*;
import org.xml.sax.*;
import BslException.*;

  class OrchidSaxErrorHandler extends BuilderErrorHandler
  {
    public void warning(SAXParseException exception) throws SAXException {
        // Bring things to a crashing halt
        throw(new SAXException("**Parsing Warning**" +
                           "  Line:    " +
                              exception.getLineNumber() + "" +
                           "  URI:     " +
                              exception.getSystemId() + "" +
                           "  Message: " +
                              exception.getMessage()));        
    }
    public void error(SAXParseException exception) throws SAXException {
        // Bring things to a crashing halt
        throw(new SAXException("**Parsing Error**" +
                           "  Line:    " +
                              exception.getLineNumber() + "" +
                           "  URI:     " +
                              exception.getSystemId() + "" +
                           "  Message: " +
                              exception.getMessage()));        
    }

    public void fatalError(SAXParseException exception) throws SAXException {
        // Bring things to a crashing halt
        throw(new SAXException("**Parsing Fatal Error**" +
                           "  Line:    " +
                              exception.getLineNumber() + "" +
                           "  URI:     " +
                              exception.getSystemId() + "" +
                           "  Message: " +
                              exception.getMessage()));        
    }
}


0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 600 total points
ID: 6985954
afair all you can get from validator is row and column numbers. after all validator is supposed to 'validate' the document - to tell you if this is a valid document or not. it is not supposed to analyze the file and try to guess what's the error.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question