Solved

How to get details of Parse Failure in Jdom?

Posted on 2002-05-02
3
161 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_
Comment Utility
I think that you can solve this problem by setting your own org.xml.sax.ErrorHandler
0
 
LVL 1

Author Comment

by:howesd
Comment Utility
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 200 total points
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now