# saxparser.h

Go to the documentation of this file.

    00001 //==========================================================================
    00002 //  SAXPARSER.H - part of
    00003 //                     OMNeT++/OMNEST
    00004 //            Discrete System Simulation in C++
    00005 //
    00006 //==========================================================================
    00007
    00008 /*--------------------------------------------------------------*
    00009   Copyright (C) 2002-2005 Andras Varga
    00010
    00011   This file is distributed WITHOUT ANY WARRANTY. See the file
    00012   `license' for details on this and other legal matters.
    00013 *--------------------------------------------------------------*/
    00014
    00015
    00016
    00017 #ifndef __SAXPARSER_H
    00018 #define __SAXPARSER_H
    00019
    00020 #include <stdio.h>
    00021
    00022 class SAXParser;
    00023
    00024
    00035 class SAXHandler
    00036 {
    00037     friend class SAXParser;
    00038   protected:
    00039     SAXParser *parser;
    00040
    00041     // internal: called from SAXParser::setHandler()
    00042     virtual void setParser(SAXParser *p) {parser=p;}
    00043
    00044   public:
    00048     SAXHandler() {parser=0;}
    00049
    00053     virtual ~SAXHandler() {}
    00054
    00058     virtual void startElement(const char *name, const char **atts)  {}
    00059
    00063     virtual void endElement(const char *name)  {}
    00064
    00068     virtual void characterData(const char *s, int len)  {}
    00069
    00073     virtual void processingInstruction(const char *target, const char *data)  {}
    00074
    00078     virtual void comment(const char *data)  {}
    00079
    00083     virtual void startCdataSection()  {}
    00084
    00088     virtual void endCdataSection()  {}
    00089 };
    00090
    00091
    00100 class SAXParser
    00101 {
    00102   protected:
    00103     char errortext[512];
    00104     SAXHandler *saxhandler;
    00105     void *currentparser;
    00106
    00107   public:
    00111     SAXParser();
    00112
    00116     void setHandler(SAXHandler *sh);
    00117
    00124     bool parse(const char *filename);
    00125
    00129     int getCurrentLineNumber();
    00130
    00134     const char *getErrorMessage()  {return errortext;}
    00135 };
    00136
    00137 #endif
    00138