OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   SAX/C++: First interface draft

[ Lists Home | Date Index | Thread Index ]
  • From: David Megginson <david@megginson.com>
  • To: XMLDev list <xml-dev-digest@ic.ac.uk>
  • Date: Thu, 2 Dec 1999 16:40:14 -0500 (EST)

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@megginson.com
           http://www.megginson.com/

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@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@ic.ac.uk the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS