Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get details of Parse Failure in Jdom?

Posted on 2002-05-02
3
Medium Priority
?
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.
Suggested Courses

704 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