Solved

How to get details of Parse Failure in Jdom?

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
stackato and cloud 4 85
HashTable highest marks enumeration alternative 9 39
arguments to jar 5 26
SHA2 certs for IIS AND Java? 2 92
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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:
This video teaches viewers about errors in exception handling.

809 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