1 // Copyright (C) 2006-2016 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_
23 #include <libxml/parser.h>
27 inline XML_Char* tochar(const xmlChar *c) { return (XML_Char*)c; };
29 // --- generic part -----------------------------------------------------------
38 //! \brief base class for parse an xml file, use a dedicated parser, runtime independant.
43 xmlReader(xmlParserBase* parser);
44 virtual void parse(std::string xmlFile);
46 xmlParserBase* _rootParser;
49 //! \brief base class for xml parsers, runtime independant
55 static void XMLCALL start_document(void* userData);
56 static void XMLCALL end_document (void* userData);
57 static void XMLCALL start_element (void* userData,
60 static void XMLCALL end_element (void* userData,
62 static void XMLCALL characters (void* userData,
65 static void XMLCALL comment (void* userData,
66 const xmlChar* value);
67 static void XMLCALL warning (void* userData,
68 const char* fmt, ...);
69 static void XMLCALL error (void* userData,
70 const char* fmt, ...);
71 static void XMLCALL fatal_error (void* userData,
72 const char* fmt, ...);
73 static void XMLCALL cdata_block (void* userData,
77 static void cleanGarbage();
78 static int getGarbageSize() {return _garbage.size(); };
80 void setAttribute(std::string key, std::string value);
81 std::string getAttribute(std::string key);
82 virtual void addData(std::string value);
83 virtual void init (const xmlChar** p, xmlParserBase* father=0);
85 std::map< std::string, int > counts;
87 static _xmlParserCtxt* _xmlParser;
88 static void XML_SetUserData(_xmlParserCtxt* ctxt,
89 xmlParserBase* parser);
91 static std::stack<xmlParserBase*> _stackParser;
94 void getAttributes(const xmlChar** p);
96 virtual void onStart (const XML_Char* elem, const xmlChar** p);
97 virtual void onEnd (const XML_Char* name);
98 virtual void charData (std::string data);
99 virtual void incrCount(const XML_Char *elem);
101 virtual void stopParse(std::string what);
104 std::map<std::string, std::string> _mapAttrib;
105 static std::list<xmlParserBase*> _garbage;
107 xmlParserBase *_father;