Solved

How to get details of Parse Failure in Jdom?

Posted on 2002-05-02
3
162 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 200 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

863 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

27 Experts available now in Live!

Get 1:1 Help Now