1 // Copyright (C) 2006-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __XMLPARSERBASE_HXX_
21 #define __XMLPARSERBASE_HXX_
26 #include <libxml/parser.h>
30 inline XML_Char* tochar(const xmlChar *c) { return (XML_Char*)c; };
32 // --- generic part -----------------------------------------------------------
41 //! \brief base class for parse an xml file, use a dedicated parser, runtime independant.
46 xmlReader(xmlParserBase* parser);
47 virtual void parse(std::string xmlFile);
49 xmlParserBase* _rootParser;
52 //! \brief base class for xml parsers, runtime independant
58 static void XMLCALL start_document(void* userData);
59 static void XMLCALL end_document (void* userData);
60 static void XMLCALL start_element (void* userData,
63 static void XMLCALL end_element (void* userData,
65 static void XMLCALL characters (void* userData,
68 static void XMLCALL comment (void* userData,
69 const xmlChar* value);
70 static void XMLCALL warning (void* userData,
71 const char* fmt, ...);
72 static void XMLCALL error (void* userData,
73 const char* fmt, ...);
74 static void XMLCALL fatal_error (void* userData,
75 const char* fmt, ...);
76 static void XMLCALL cdata_block (void* userData,
80 static void cleanGarbage();
81 static int getGarbageSize() {return _garbage.size(); };
83 void setAttribute(std::string key, std::string value);
84 std::string getAttribute(std::string key);
85 virtual void addData(std::string value);
86 virtual void init (const xmlChar** p, xmlParserBase* father=0);
88 std::map< std::string, int > counts;
90 static _xmlParserCtxt* _xmlParser;
91 static void XML_SetUserData(_xmlParserCtxt* ctxt,
92 xmlParserBase* parser);
94 static std::stack<xmlParserBase*> _stackParser;
97 void getAttributes(const xmlChar** p);
99 virtual void onStart (const XML_Char* elem, const xmlChar** p);
100 virtual void onEnd (const XML_Char* name);
101 virtual void charData (std::string data);
102 virtual void incrCount(const XML_Char *elem);
104 virtual void stopParse(std::string what);
107 std::map<std::string, std::string> _mapAttrib;
108 static std::list<xmlParserBase*> _garbage;
110 xmlParserBase *_father;