Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Figuring out errors during XML validation

Reply
Thread Tools

Figuring out errors during XML validation

 
 
PBR
Guest
Posts: n/a
 
      03-06-2006
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)

 
Reply With Quote
 
 
 
 
steve_marjoribanks
Guest
Posts: n/a
 
      03-06-2006
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.

 
Reply With Quote
 
 
 
 
PBR
Guest
Posts: n/a
 
      03-07-2006

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..?c an u
give an example? (I am using ErrorHandler interface)

 
Reply With Quote
 
steve_marjoribanks
Guest
Posts: n/a
 
      03-07-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Figuring out which form button was pressed darrel ASP .Net 19 01-30-2006 04:15 PM
Figuring out Javascript Errors Shahid Juma HTML 12 06-01-2004 06:40 PM
Need help figuring out scope in Java rboelio Java 1 02-03-2004 04:57 AM
trouble figuring out HttpURLConnection Flip Java 8 11-13-2003 05:33 AM
Figuring Out Why My Program Eats So Much Memory Dale Java 4 09-25-2003 02:11 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57