Modeler Extensions Framework
XMLHelper.h
Go to the documentation of this file.
1 //============================================================================
2 // Licensed Materials - Property of IBM
3 //
4 // IBM SPSS Products: Modeler
5 //
6 // (C) Copyright IBM Corp. 1994, 2014
7 //
8 // US Government Users Restricted Rights - Use, duplication or disclosure restricted
9 // by GSA ADP Schedule Contract with IBM Corp.
10 //============================================================================
11 /*
12  Modeler Extensions Framework C++ Helpers (XMLHelper.h)
13 */
14 
15 #ifndef XML_HELPER_H
16 #define XML_HELPER_H
17 
18 #include "clemext.h"
19 #include <string>
20 
24 namespace ClemextCppHelper {
25 
26  // maintain a shared count of how many clients are accessing a resource
27 
28  struct AccessCount {
29  AccessCount();
30  void dec();
31  void inc();
32  unsigned value();
33  unsigned *value_;
34  };
35 
36 
39  class XMLException {
40  std::string message_;
41 
42  public:
44  XMLException(std::string message) : message_("") { message_ = message; }
45  std::string getMessage() { return message_; }
46  };
47 
48  class XMLElement;
49 
52  CLEMEXTXMLIterator *iter_;
53  AccessCount count_;
54  public:
55  XMLElementIterator(CLEMEXTXMLIterator *);
56 
61 
66 
67  virtual ~XMLElementIterator();
68 
72  bool hasMore();
73 
77  XMLElement next();
78 
81  void deleteCurrentItem();
82 
85  virtual void close();
86 
87  };
88 
91  CLEMEXTXMLIterator *iter_;
92  AccessCount count_;
93  public:
94  XMLTextIterator(CLEMEXTXMLIterator *);
95 
99  XMLTextIterator(const XMLTextIterator &other);
100 
105 
106  virtual ~XMLTextIterator();
107 
111  bool hasMore();
112 
116  const char *next();
117 
120  void deleteCurrentItem();
121 
124  virtual void close();
125 
126  };
127 
129  class XMLElement {
130  protected:
131  CLEMEXTXML *item_;
132  public:
136  XMLElement(CLEMEXTXML *item=NULL);
137 
139  virtual ~XMLElement();
140 
143  void getName(std::string &name);
144 
148  bool hasAttribute(const std::string &name);
149 
154  void getAttribute(const std::string &name,std::string &value);
155 
159  std::string getAttribute(const std::string &name);
160 
164  XMLElement getElementByAttribute(const std::string name, const std::string &attr_name, const std::string attr_value);
165 
172  bool getAttribute(const std::string &name,CLEMEXTReal &value);
173 
180  bool getAttribute(const std::string &name,CLEMEXTInteger &value);
181 
186  void addAttribute(const std::string &name,const std::string &value);
187 
192  void addAttribute(const std::string &name,CLEMEXTInteger value);
193 
197  void removeAttribute(const std::string &name);
198 
205  XMLElementIterator getElements(const std::string &name);
206 
213 
218  XMLElement addElement(const std::string &name);
219 
223  void addText(const std::string &data);
224 
228  bool isValid() const;
229 
237  XMLElement getElement(const std::string &name);
238 
244  XMLElement getElement(const std::string &name, int index);
245  };
246 
248  class XMLDocument : public XMLElement {
249  AccessCount count_;
250  public:
254  XMLDocument(CLEMEXTXML *item = NULL);
255 
259  XMLDocument(const XMLDocument &other);
260 
264  XMLDocument &operator=(const XMLDocument &other);
265 
267  virtual ~XMLDocument();
268 
270  void dispose();
271 
277  static XMLDocument createFromString(CLEMEXTHost *host,const char *str);
278 
284  static XMLDocument createNew(CLEMEXTHost *host,const char *root_element_name);
285 
289  void doc2string(std::string &str);
290 
291  };
292 }
293 #endif
void addText(const std::string &data)
XMLElementIterator getElements(const std::string &name)
XMLElementIterator(CLEMEXTXMLIterator *)
double CLEMEXTReal
Definition: clemext.h:111
XMLTextIterator & operator=(const XMLTextIterator &other)
XMLException(std::string message)
Definition: XMLHelper.h:44
XMLElement getElement(const std::string &name)
XMLDocument(CLEMEXTXML *item=NULL)
XMLElement(CLEMEXTXML *item=NULL)
long long CLEMEXTInteger
Definition: clemext.h:116
XMLElementIterator & operator=(const XMLElementIterator &other)
XMLDocument & operator=(const XMLDocument &other)
void getAttribute(const std::string &name, std::string &value)
void addAttribute(const std::string &name, const std::string &value)
XMLElement getElementByAttribute(const std::string name, const std::string &attr_name, const std::string attr_value)
static XMLDocument createFromString(CLEMEXTHost *host, const char *str)
void removeAttribute(const std::string &name)
XMLTextIterator(CLEMEXTXMLIterator *)
XMLElement addElement(const std::string &name)
XMLTextIterator getTextSections()
static XMLDocument createNew(CLEMEXTHost *host, const char *root_element_name)
void doc2string(std::string &str)
void getName(std::string &name)
bool hasAttribute(const std::string &name)