Re: SAX: Error Reporting (question 4 of 10)

James Clark (jjc@jclark.com)
Sun, 04 Jan 1998 06:56:35 +0700


David Megginson wrote:
>
> Should SAX treat errors as events? If so, should it distinguish fatal
> errors from warnings or non-fatal errors?
>
> public void warning (String message, String systemID, int line);
> public void fatalError (String message, String systemID, int line);

There are 3 things that need to be distinguished:

- Fatal errors: violations of well-formedness constraints; processors
have to detect these and must stop normal processing. In Java I think
an exception is the only reasonable way to handle these. Unless you do
this people will be tempted to continue processing in violation of the
spec.

- Errors: violations of validity constraints or other errors that a
processor is not required to detect.

- Warnings: messages about conditions that do not cause a document to be
non-conforming.

To do a really good job of reporting these, much more information is
needed that a line number and a URL. In particular you need more
information about the entity structure. For example, given a document
doc.xml:

<!DOCTYPE doc SYSTEM "doc.dtd">
<doc>&e;</doc>

and doc.dtd:

<!ELEMENT doc (a)>
<!ENTITY e "<b/>">

nsgmls -e will say:

In entity e included from doc.xml:2:8
nsgmls:doc.dtd:2:15:E: element "b" undefined

There can be more than one relevant URL and line number.

This sort of facility also introduces major internationalization issues.

I can guarantee you are not going to be able to do a good job of error
reporting and still keep the interface simple.

James