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_
24 // --- select only one of the following packages ------------------------------
25 // - libxml2 comes with gnome, so it's almost always already installed,
26 // but may not not work (see below).
27 // - libexpat is a less common package, but light, and works fine.
29 // With standard installation of libxml2, C++ exception cannot be catched
30 // during the parse process. This is required for normal use of yacs.
31 // libxml2 must be generated with configure --with-fexceptions ...
33 // Developpement and tests are done with libexpat.
38 // --- specific part for libxml2 ----------------------------------------------
43 #include <libxml/parser.h>
47 inline XML_Char* tochar(const xmlChar *c) { return (XML_Char*)c; };
50 // --- specific part for expat ------------------------------------------------
54 #define xmlChar XML_Char
55 inline const XML_Char* tochar(const xmlChar *c) { return c; };
59 // --- generic part -----------------------------------------------------------
68 //! \brief base class for parse an xml file, use a dedicated parser, runtime independant.
73 xmlReader(xmlParserBase* parser);
74 virtual void parse(std::string xmlFile);
76 xmlParserBase* _rootParser;
79 //! \brief base class for xml parsers, runtime independant
85 static void XMLCALL start_document(void* userData);
86 static void XMLCALL end_document (void* userData);
87 static void XMLCALL start_element (void* userData,
90 static void XMLCALL end_element (void* userData,
92 static void XMLCALL characters (void* userData,
95 static void XMLCALL comment (void* userData,
96 const xmlChar* value);
97 static void XMLCALL warning (void* userData,
98 const char* fmt, ...);
99 static void XMLCALL error (void* userData,
100 const char* fmt, ...);
101 static void XMLCALL fatal_error (void* userData,
102 const char* fmt, ...);
103 static void XMLCALL cdata_block (void* userData,
104 const xmlChar* value,
107 static void cleanGarbage();
108 static int getGarbageSize() {return _garbage.size(); };
110 void setAttribute(std::string key, std::string value);
111 std::string getAttribute(std::string key);
112 virtual void addData(std::string value);
113 virtual void init (const xmlChar** p, xmlParserBase* father=0);
115 std::map< std::string, int > counts;
118 static _xmlParserCtxt* _xmlParser;
119 static void XML_SetUserData(_xmlParserCtxt* ctxt,
120 xmlParserBase* parser);
124 static XML_Parser _xmlParser;
127 static std::stack<xmlParserBase*> _stackParser;
130 void getAttributes(const xmlChar** p);
132 virtual void onStart (const XML_Char* elem, const xmlChar** p);
133 virtual void onEnd (const XML_Char* name);
134 virtual void charData (std::string data);
135 virtual void incrCount(const XML_Char *elem);
137 virtual void stopParse(std::string what);
140 std::map<std::string, std::string> _mapAttrib;
141 static std::list<xmlParserBase*> _garbage;
143 xmlParserBase *_father;