finalising org.sax.xml.Parser

David Megginson ak117 at
Tue Feb 24 13:59:52 GMT 1998

Michael Kay writes:

 > Comments:
 > 1. Is the (ch, start, length) method really necessary, given that one can
 > supply a StringReader or whatever to the parse(InputStream) method?

James has convinced me that it's not -- I'm actually happy to drop it,
since I want to keep the interfaces as simple as possible both to
learn and to implement.

 > 2. If my "main" XML document is in a record in a database, then it is very
 > likely that any other entities referred to will be in the database as well.
 > Therefore, I think the logical approach in this situation is for the
 > application to resolve all URIs encountered: the parser should call the
 > application supplying a URI and the application should return an InputStream
 > to allow the parser to read it. This should presumably be done via the
 > EntityHandler interface.

I have considered this approach, but I can anticipate two problems:

1) It puts the burdon of resolving URIs on the application rather than
   the parser.

2) It is possible that some programming languages or libraries do not
   represent network connections as input streams.

If (2) isn't a problem, we might find a way to work around (1).  I'll
be coming back to the EntityHandler interface in a future posting, and
we can take up the issue again then.

 > And a question: is there a recommended way to abort a parse once the
 > application has got the information it needs (e.g extracting the contents of
 > the TITLE element)? Would an interface like parser.abort() be cleaner than
 > playing around with exceptions? I ask because in handling the results of a
 > free text search, I am parsing all the retrieved documents when I only need
 > a bit of text from the beginning of each, and this is obviously wasteful. I
 > thought perhaps of supplying a stream and generating a premature
 > end-of-file, and then trapping the exception that comes back.

In languages that support exceptions (Java, C++, Perl, and sort-of C),
an exception is probably the cleanest way to handle this.  It also
lets you pass application-specific information back to the top level
within your exception.

All the best,


David Megginson                 ak117 at
Microstar Software Ltd.         dmeggins at

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at
Archived as:
To (un)subscribe, mailto:majordomo at the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at

More information about the Xml-dev mailing list