Version: 9.16.0
xmlParserBase.hxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
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.
7//
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.
12//
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
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#ifndef __XMLPARSERBASE_HXX_
21#define __XMLPARSERBASE_HXX_
22
23#include <libxml/parser.h>
24
25#define XMLCALL
26#define XML_Char char
27inline XML_Char* tochar(const xmlChar *c) { return (XML_Char*)c; };
28
29// --- generic part -----------------------------------------------------------
30
31#include <string>
32#include <map>
33#include <stack>
34#include <list>
35
36class xmlParserBase;
37
39
41{
42public:
43 xmlReader(xmlParserBase* parser);
44 virtual void parse(std::string xmlFile);
45protected:
47};
48
50
52{
53public:
54#ifndef SWIG
55 static void XMLCALL start_document(void* userData);
56 static void XMLCALL end_document (void* userData);
57 static void XMLCALL start_element (void* userData,
58 const xmlChar* name,
59 const xmlChar** p);
60 static void XMLCALL end_element (void* userData,
61 const xmlChar* name);
62 static void XMLCALL characters (void* userData,
63 const xmlChar* ch,
64 int len);
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,
74 const xmlChar* value,
75 int len);
76#endif
77 static void cleanGarbage();
78 static int getGarbageSize() {return _garbage.size(); };
79public:
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);
84
85 std::map< std::string, int > counts;
86
87 static _xmlParserCtxt* _xmlParser;
88 static void XML_SetUserData(_xmlParserCtxt* ctxt,
89 xmlParserBase* parser);
90
91 static std::stack<xmlParserBase*> _stackParser;
92
93protected:
94 void getAttributes(const xmlChar** p);
95
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);
100 virtual void end();
101 virtual void stopParse(std::string what);
102
103protected:
104 std::map<std::string, std::string> _mapAttrib;
105 static std::list<xmlParserBase*> _garbage;
106 std::string _data;
108};
109
110#endif
base class for xml parsers, runtime independant
static void XML_SetUserData(_xmlParserCtxt *ctxt, xmlParserBase *parser)
virtual void onStart(const XML_Char *elem, const xmlChar **p)
static void XMLCALL start_element(void *userData, const xmlChar *name, const xmlChar **p)
static int getGarbageSize()
virtual void end()
virtual void stopParse(std::string what)
static void XMLCALL end_element(void *userData, const xmlChar *name)
static void XMLCALL start_document(void *userData)
static void XMLCALL characters(void *userData, const xmlChar *ch, int len)
static _xmlParserCtxt * _xmlParser
xmlParserBase * _father
static void XMLCALL error(void *userData, const char *fmt,...)
std::string _data
virtual void addData(std::string value)
static void XMLCALL fatal_error(void *userData, const char *fmt,...)
virtual void onEnd(const XML_Char *name)
static std::list< xmlParserBase * > _garbage
void setAttribute(std::string key, std::string value)
static void cleanGarbage()
static std::stack< xmlParserBase * > _stackParser
std::map< std::string, std::string > _mapAttrib
void getAttributes(const xmlChar **p)
static void XMLCALL comment(void *userData, const xmlChar *value)
static void XMLCALL cdata_block(void *userData, const xmlChar *value, int len)
virtual void init(const xmlChar **p, xmlParserBase *father=0)
std::string getAttribute(std::string key)
static void XMLCALL end_document(void *userData)
static void XMLCALL warning(void *userData, const char *fmt,...)
virtual void charData(std::string data)
std::map< std::string, int > counts
virtual void incrCount(const XML_Char *elem)
base class for parse an xml file, use a dedicated parser, runtime independant.
virtual void parse(std::string xmlFile)
xmlParserBase * _rootParser
xmlReader(xmlParserBase *parser)
Proc * p
Definition: driver.cxx:216
XML_Char * tochar(const xmlChar *c)
#define XML_Char
#define XMLCALL