Julien Buchanan <[EMAIL PROTECTED]> wrote on 03/27/2007 08:37:09 AM:

> Thanks for the information.
> This indeed gives me the line/col position where Xerces throws the
> exception,
> which turns out to often be inside the element qname and not at an
> element start or end. So:
> 
> a) i need to highlight the offending elements and thus need to know
> where they start and end. is there a way inside my startElement and
> endElement handlers to get the position info too? (i don't have an
> exception there that carries the info)

If there's a well-formedness error within the start-tag the parser will 
stop processing the document before it reaches the end of the start-tag. 
If you turn on the continue-after-fatal-error [1] feature you might be 
able to get the location information you're looking for from the Locator 
[2], though it might be misleading given that the document isn't 
well-formed.

> b) is there a way to get an error type id (ideally something numeric) or
> do i have to regexp-match each SAXParseException's message against every
> known error string to know what type of sax parsing error it is (e.g.
> missing end-tag, invalid character, etc.)?

Not something you can get through SAX. I vaguely remember that there was 
an attempt to define such things in a SAX 2.1 but it never ended up 
happening. Internally, every error message Xerces emits has a unique 
identifier (a tuple of a domain and a key) associated with it. This error 
ID is accessible through XNI. You may want to take a look at 
XMLErrorHandler [1].

> Michael Glavassevich wrote:
> > The SAXParseExceptions [1] reported to your ErrorHandler and thrown by 
the 
> > XMLReader contain location information. See getColumnNumber() and 
> > getLineNumber().
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

[1] 
http://xerces.apache.org/xerces2-j/features.html#continue-after-fatal-error
[2] 
http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/Locator.html
[3] 
http://xerces.apache.org/xerces2-j/javadocs/xni/org/apache/xerces/xni/parser/XMLErrorHandler.html


Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to