Modeler Extensions Framework
XMLHelper.h
Go to the documentation of this file.
1 //============================================================================
2 // IBM Confidential
3 //
4 // OCO Source Materials
5 //
6 // IBM SPSS Products: Modeler Common
7 //
8 // (C) Copyright IBM Corp. 1994, 2011
9 //
10 // The source code for this program is not published or otherwise divested of its trade secrets,
11 // irrespective of what has been deposited with the U.S. Copyright Office.
12 //============================================================================
13 /*
14  Copyright (c) Integral Solutions Ltd 2006-2008
15  Clementine Extensions Framework C++ Helpers (XMLHelper.h)
16  Version 12.0.1
17 */
18 
19 #ifndef XML_HELPER_H
20 #define XML_HELPER_H
21 
22 #include "clemext.h"
23 #include <string>
24 
28 namespace ClemextCppHelper {
29 
30  // maintain a shared count of how many clients are accessing a resource
31 
32  struct AccessCount {
33  AccessCount();
34  void dec();
35  void inc();
36  unsigned value();
37  unsigned *value_;
38  };
39 
40 
43  class XMLException {
44  std::string message_;
45 
46  public:
48  XMLException(std::string message) : message_("") { message_ = message; }
49  std::string getMessage() { return message_; }
50  };
51 
52  class XMLElement;
53 
56  CLEMEXTXMLIterator *iter_;
57  AccessCount count_;
58  public:
59  XMLElementIterator(CLEMEXTXMLIterator *);
60 
65 
70 
71  virtual ~XMLElementIterator();
72 
76  bool hasMore();
77 
81  XMLElement next();
82 
85  void deleteCurrentItem();
86 
89  virtual void close();
90 
91  };
92 
95  CLEMEXTXMLIterator *iter_;
96  AccessCount count_;
97  public:
98  XMLTextIterator(CLEMEXTXMLIterator *);
99 
103  XMLTextIterator(const XMLTextIterator &other);
104 
109 
110  virtual ~XMLTextIterator();
111 
115  bool hasMore();
116 
120  const char *next();
121 
124  void deleteCurrentItem();
125 
128  virtual void close();
129 
130  };
131 
133  class XMLElement {
134  protected:
135  CLEMEXTXML *item_;
136  public:
140  XMLElement(CLEMEXTXML *item=NULL);
141 
143  virtual ~XMLElement();
144 
147  void getName(std::string &name);
148 
152  bool hasAttribute(const std::string &name);
153 
158  void getAttribute(const std::string &name,std::string &value);
159 
163  std::string getAttribute(const std::string &name);
164 
168  XMLElement getElementByAttribute(const std::string name, const std::string &attr_name, const std::string attr_value);
169 
176  bool getAttribute(const std::string &name,CLEMEXTReal &value);
177 
184  bool getAttribute(const std::string &name,CLEMEXTInteger &value);
185 
190  void addAttribute(const std::string &name,const std::string &value);
191 
196  void addAttribute(const std::string &name,CLEMEXTInteger value);
197 
201  void removeAttribute(const std::string &name);
202 
209  XMLElementIterator getElements(const std::string &name);
210 
217 
222  XMLElement addElement(const std::string &name);
223 
227  void addText(const std::string &data);
228 
232  bool isValid() const;
233 
241  XMLElement getElement(const std::string &name);
242 
248  XMLElement getElement(const std::string &name, int index);
249  };
250 
252  class XMLDocument : public XMLElement {
253  AccessCount count_;
254  public:
258  XMLDocument(CLEMEXTXML *item = NULL);
259 
263  XMLDocument(const XMLDocument &other);
264 
268  XMLDocument &operator=(const XMLDocument &other);
269 
271  virtual ~XMLDocument();
272 
274  void dispose();
275 
281  static XMLDocument createFromString(CLEMEXTHost *host,const char *str);
282 
288  static XMLDocument createNew(CLEMEXTHost *host,const char *root_element_name);
289 
293  void doc2string(std::string &str);
294 
295  };
296 }
297 #endif
void addText(const std::string &data)
XMLElementIterator getElements(const std::string &name)
XMLElementIterator(CLEMEXTXMLIterator *)
double CLEMEXTReal
Definition: clemext.h:113
XMLTextIterator & operator=(const XMLTextIterator &other)
XMLException(std::string message)
Definition: XMLHelper.h:48
XMLElement getElement(const std::string &name)
XMLDocument(CLEMEXTXML *item=NULL)
XMLElement(CLEMEXTXML *item=NULL)
long long CLEMEXTInteger
Definition: clemext.h:118
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)