[fpc-devel]SAX poll

Sebastian Günther sguenther at gmx.de
Thu Nov 23 17:02:22 CET 2000


Hello *,

I need everybody's opinion on a new unit which will be available soon:

SAX is the Simple API for XML. It defines an interface for XML parsers,
which use callbacks to report events such as 'start tag processed',
'comment processed' and so on. There shouls be some parsers around which
are compatible to SAX, but most of them are written in Java.

In SAX, events are being reported by calling methods of a special
interface. Applications register these interfaces at the parser at
startup. Such an interface looks like this:

  ISAXErrorHandler = interface
    procedure Error(AException: ESAXParseException);
    procedure FatalError(AException: ESAXParseException);
    procedure Warning(AException: ESAXParseException);
  end;

I have a FPC version almost finished, but now, that the main branch
compiler supports interfaces, some questions remain:

1. Implementation with interfaces or classes
It would be possible to define _all_ SAX interfaces, including the ones
for the parser, as interface in FPC. The other option would be to define
only the callback interfaces as interface, everything else uses classes.
Using interfaces everywhere would be more conformant to SAX, but the
latter solution is faster. The first one only makes sense, if somebody
plans to use a different SAX parser than the default one with FPC. (the
parser itself won't be included in the SAX unit, it will be possible to
use different parsers with the upcoming SAX unit anyway. But using the
classes approach, all parsers must be written explicitly for this SAX
unit.)

2. Using callback interfaces or method properties
If the FPC SAX unit won't use interfaces everywhere, it must be
considered to dump the callback interfaces as well: Java etc. need such
callback interfaces, as they don't know the concept of 'method
properties', i.e. properties or fields in classes which store a method
pointer. But as FPC is more powerful than 'those other languages', we
could use such properties instead. For example, for the ErrorHandler
case, the XMLReader.SetErrorHandler and XMLReader.GetErrorHandler
methods would be replaced by something like this:

  TSAXXMLReader = class
    ...
    property OnError(AException: ESAXParseException) read ... write ...;
    property OnFatalError(AException: ESAXParseException) read ... write
...;
    property OnWarning(AException: ESAXParseException) read ... write
...;
  end;


I'm personally are in favour of the more ObjectPascal specific
solutions, as they are faster and better to use within Pascal programs.


Your opinions, please...? :)


- Sebastian





More information about the fpc-devel mailing list