SAX/C++: First interface draft

David Megginson david at megginson.com
Thu Dec 2 21:41:27 GMT 1999


I have just drafted this interface, and haven't even run it through a
C++ compiler yet.  For clarity, I've omitted constructors and
destructors, as well as most of what will be inline implementations.

Notes: I haven't looked at other C++ efforts yet, but I will try to do
so now.  Eventually, this should be in a special C++ namespace.

sax.h
====================8<====================8<====================
#ifndef __SAX_HXX
#define __SAX_HXX

#include <istream>

class InputSource
{
public:
  virtual const char * getPublicId (void) const;
  virtual void setPublicId (const char * publicId);

  virtual const char * getSystemId (void) const;
  virtual void setSystemId (const char * systemId);

  virtual std::istream * getInputStream (void) const;
  virtual void setInputStream (std::istream * in);

protected:
  const char * _publicId;
  const char * _systemId;
  std::istream * _in;
};


class AttributeList
{
public:
  virtual size_t getLength (void) const = 0;

  virtual const char * getName (size_t pos) const = 0;
  virtual const char * getType (size_t pos) const = 0;
  virtual const char * getValue (size_t pos) const = 0;

  virtual const char * getType (const char * name) const;
  virtual const char * getValue (const char * name) const;
};


class SAXException
{
public:
  virtual const char * getMessage (void) const;
protected:
  const char * _message;
};


class SAXParseException : public SAXException
{
public:
  virtual const char * getPublicId (void) const;
  virtual const char * getSystemId (void) const;
  virtual const size_t getLineNumber (void) const;
  virtual const size_t getColumnNumber (void) const;

protected:
  const char * _publicId;
  const char * _systemId;
  const size_t _lineNumber;
  const size_t _columnNumber;
};


class EntityResolver
{
public:
  virtual const InputSource * resolveEntity (const char * publicId,
					     const char * systemId);
};


class DTDHandler
{
public:
  virtual void notationDecl (const char * name,
			     const char * publicId,
			     const char * systemId) {}
  virtual void unparsedEntityDecl (const char * name,
				   const char * publicId,
				   const char * systemId,
				   const char * notationName) {}
};


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

protected:
  Locator * _locator;
};


class ErrorHandler
{
public:
  virtual void warning (const SAXParseException &e) {}
  virtual void error (const SAXParseException &e) {}
  virtual void fatalError (const SAXParseException &e) {}
};


class Parser
{
public:
  // setLocale??

  virtual void setEntityResolver (EntityResolver &resolver);
  virtual void setDTDHandler (DTDHandler &handler);
  virtual void setDocumentHandler (DocumentHandler &handler);
  virtual void setErrorHandler (ErrorHandler &handler);

  virtual void parse (const char * systemId);
  virtual void parse (const InputSource &input) = 0;

protected:
  EntityResolver * _resolver;
  DTDHandler * _dtdHandler;
  DocumentHandler * _documentHandler;
  ErrorHandler * _errorHandler;
};

#endif
====================8<====================8<====================

Comments?


All the best,


David

-- 
David Megginson                 david at megginson.com
           http://www.megginson.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