You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Avitzur Alon <Al...@icomverse.com> on 2003/12/03 06:52:59 UTC

Error codes from the parser

Is it possible to obtain the error code from the SAXParseException, other
than parsing the error message?

Thanks,
Alon.

Re: Error codes from the parser

Posted by Andy Clark <an...@apache.org>.
Michael Glavassevich wrote:
> The short answer is no, [...]

The long answer is yes. :)

There is an internal component in Xerces called
the XMLErrorReporter that is used to generate a
human-readable error message from an internal id.
This is the default behavior. However, you can
provide your own error reporter that simply
generates an error message from the id that is
passed in.

The various Xerces components call a method on
the error reporter when an error occurs. Here's a
list of things that are passed:

   * severity {warning, error, fatal error}
   * domain (string)
   * key (string)
   * replacement parameters (array of objects)

The idea is that each error has a specific key
within a domain. Both of these values are given
as strings. In general, we try to use URLs to the
specs that define the error (e.g. the URL to the
XML spec) and the key is an anchor within that
document. However, these documents really don't
have anchors at all of the places where we'd like,
so the keys are just unique ids for our use.

Anyway, you can implement an error handler that
does not localize an error message but rather
generates an error message that is just the
error identifier. For full debuggability, I would
suggest the following:

   StringBuffer msg = new StringBuffer();
   msg.append(domain);
   msg.append('#');
   msg.append(key);
   for (int i = 0; i < params.length; i++) {
     msg.append('\t');
     msg.append(String.valueOf(params[i]));
   }

I'm doing this from memory so forgive me if I
get some of the details wrong. Check the docs and
the source code for specifics.

Hope this helps (and works)!

-- 
Andy Clark * andyc@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Error codes from the parser

Posted by Michael Glavassevich <mr...@apache.org>.
Hello Alon,

The short answer is no, however if you have a look at the SAX website [1]
the latest docs state that SAX 2.1 (a version which doesn't exist yet as
far as I know) defines something called exception IDs that you can use
to identify the error emitted by the parser. The identifiers are strings
which correspond to the well-formedness and validity constraint rules from
the XML 1.0 and XML Namespaces rec, but no official list has been
generated. I'm not sure what the plan is for another version of SAX, but
it doesn't seem like it will be completed anytime soon. You could always
ask a question on the SAX mailing lists [2].

Hope that helps.

[1] http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html
[2] http://sourceforge.net/projects/sax/

On Wed, 3 Dec 2003, Avitzur Alon wrote:

> Is it possible to obtain the error code from the SAXParseException, other
> than parsing the error message?
>
> Thanks,
> Alon.

---------------------------
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org