SAX/C++: First interface draft

Didier PH Martin martind at netfolder.com
Sun Dec 12 21:53:06 GMT 1999


Hi David,

Why not implement the document handler also as an interface? thus we we
woudl have:

class IDocumentHandler
{
public:
  virtual void setDocumentLocator (const Locator &locator) = 0;
  virtual void startDocument (void) = 0;
  virtual void endDocument (void) = 0;
  virtual void startElement (const char * name, const AttributeList &atts) =
0;
  virtual void endElement (const char * name) = 0;
  virtual void characters (const char * ch, size_t length) = 0;
  virtual void ignorableWhitespace (const char * ch, size_t length) = 0;
  virtual void processingInstruction (const char * target, const char *
data) = 0;
}

class MyDocHandlerImp : public IDocumentHandler
{
  MyDocHandlerImp();
  ~MyDocHandlerImp();
  void setDocumentLocator (const Locator &locator);
  void startDocument (void);
  void endDocument (void);
  void startElement (const char * name, const AttributeList &atts);
  void endElement (const char * name);
  void characters (const char * ch, size_t length);
  void ignorableWhitespace (const char * ch, size_t length);
  void processingInstruction (const char * target, const char * data);
protected:
  Locator * _locator;
}

PRO and CON:
------------
The event generator talks to a generic interface not to a particular
implementation. However this reauires that the interface.h to be included
and that interfaces are inherited by implementations.

Other point of view:
--------------------
SP uses an event record which tend to reduce the number of interface
members. In the OpenJade project, we are thinking to remake the C++
interface of OpenSP as follow:

class IDocumentHandler
{
  virtual void startElement(const StartElementEvent &event) = 0;
  virtual void endElement(const EndElementEvent &) = 0;
}

class parser: public IDocumentHandler, public SGML_XML_Application
{
	void startElement((const StartElementEvent &event);
	void endElement(const EndElementEvent &);
}
note: the usage of an interface also allows the class implementation to use
multiple inheritence and still be able to be interfaced with the client
without problems, this may not be the case for an ordinary class.

This is the event record which provide description of the event type. I
understand that SAX saw its origins as a set of Java classes. Would it be to
alien to SAX to use structs intead of methods? (just asking with curiosity
and trying to make these world compatible and useful to developers)

Cheers
Didier PH Martin
mailto:martind at netfolder.com
http://www.netfolder.com


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To unsubscribe, mailto:majordomo at ic.ac.uk the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)





More information about the Xml-dev mailing list