Figuring out errors during XML validation

Discussion in 'XML' started by PBR, Mar 6, 2006.

  1. PBR

    PBR Guest

    How can I capture the Element name, and generate meaningful error
    messages, when a validation error occurrs.I am using java APIs to
    validate (javax.xml.validation)
    PBR, Mar 6, 2006
    #1
    1. Advertising

  2. You can use methods such as exception.getMessage(),
    exception.getLineNumber etc.to get information about an exception.

    I'd recommend using the ErrorHandler interface if you're using an
    XMLReader.
    steve_marjoribanks, Mar 6, 2006
    #2
    1. Advertising

  3. PBR

    PBR Guest

    Steve Thanks for ur reply.
    will i be able to get the element name where validation error had
    occured if i use exception.getMessage(),exception.getLineNumber..?can u
    give an example? (I am using ErrorHandler interface)
    PBR, Mar 7, 2006
    #3
  4. Um, yeah I'm fairly certain it gives a validation error message which
    includes the element name, I'm sorry I don't have any examples to hand
    but try something along the lines of:

    class ParserErrors implements ErrorHandler
    {
    public void warning (SAXParseException e)
    {
    System.out.println("Warning!, Line: " + e.getLineNumber() +
    "\nMessage: " + e.getMessage);
    }

    public void error (SAXParseException e)
    {
    etc....
    }

    public void fatalError (SAXParseException e)
    {
    etc...
    }
    }


    and just try validating an invalid XML file and see what it gives you.
    There are other methods available as well such as getColumnNumber(),
    just take a look at the API. Use can use the results of these methods
    in any way you want.

    Steve
    steve_marjoribanks, Mar 7, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darrel
    Replies:
    19
    Views:
    591
    darrel
    Jan 30, 2006
  2. Dale
    Replies:
    4
    Views:
    356
  3. Flip
    Replies:
    8
    Views:
    665
  4. rboelio
    Replies:
    1
    Views:
    338
    Andrew Thompson
    Feb 3, 2004
  5. Shahid Juma

    Figuring out Javascript Errors

    Shahid Juma, May 31, 2004, in forum: HTML
    Replies:
    12
    Views:
    577
    Weyoun the Dancing Borg
    Jun 1, 2004
Loading...

Share This Page