ADTF
Loading...
Searching...
No Matches
dom.h
Go to the documentation of this file.
1
15
16#ifndef A_UTILS_UTIL_XML_DOM_HEADER_INCLUDED_
17#define A_UTILS_UTIL_XML_DOM_HEADER_INCLUDED_
18
19#include <a_util/base/enums.h>
21
22#include <list>
23#include <map>
24#include <stdexcept>
25
26namespace a_util {
27namespace xml {
28class DOM;
29class DOMElement;
30
32class DOMException : public std::runtime_error {
33public:
38 DOMException(const std::string& what);
39};
40
42typedef std::list<DOMElement> DOMElementList;
44typedef std::map<std::string, std::string> DOMAttributes;
45
48public:
51
54
59 DOMElement(const DOMElement& element);
60
67
74 std::string getAttribute(const std::string& name,
75 const std::string& def_value = std::string()) const;
76
82
88 DOMElement getChild(const std::string& name) const;
89
95
100 std::string getData() const;
101
106 DOM getDocument() const;
107
112 std::string getName() const;
113
119
124 std::string getPath() const;
125
134 bool setAttribute(const std::string& name, const std::string& strValue);
135
143 bool setData(const std::string& data);
144
152 bool setName(const std::string& name);
153
159 bool hasAttribute(const std::string& name) const;
160
166 bool eraseAttribute(const std::string& name);
167
208 bool findNode(const std::string& query, DOMElement& element_ptr) const;
209
218 bool findNodes(const std::string& query, DOMElementList& elements) const;
219
225 bool sortNodes(const std::string& query, SortingOrder order);
226
235 bool sortNodes(const std::string& query, SortingOrder order, std::size_t number_of_nodes);
236
245 std::size_t sortNodes(const std::string& query,
246 const std::string& attribute,
247 SortingOrder order);
248
261 bool sortNodes(const std::string& query,
262 const std::string& attribute,
263 SortingOrder order,
264 std::size_t number_of_nodes);
265
271 DOMElement createChild(const std::string& name);
272
279 DOMElement createChildBefore(const std::string& name, const DOMElement& before);
280
286 bool removeChild(const std::string& name);
287
292 bool isNull() const;
293
294private:
301 friend bool operator==(const DOMElement& lhs, const DOMElement& rhs);
302
303private:
304 class Implementation;
306 friend class DOM;
307};
308
315bool operator!=(const DOMElement& lhs, const DOMElement& rhs);
316
318class DOM {
319public:
322
325
330 DOM(const DOM& dom);
331
337 DOM& operator=(const DOM& dom);
338
344 bool load(const std::string& file_path);
345
351 bool save(const std::string& file_path) const;
352
358 bool fromString(const std::string& xml);
359
364 std::string toString() const;
365
370 void reset();
371
376 DOMElement getRoot() const;
377
386 bool findNode(const std::string& query, DOMElement& element_ptr) const;
387
396 bool findNodes(const std::string& query, DOMElementList& elements) const;
397
402 std::string getLastError() const;
403
408 bool isNull() const;
409
410private:
411 class Implementation;
413 friend class DOMElement;
414};
415
422bool operator==(const DOM& lhs, const DOM& rhs);
423
430bool operator!=(const DOM& lhs, const DOM& rhs);
431
432} // namespace xml
433} // namespace a_util
434
435#endif // A_UTILS_UTIL_XML_DOM_HEADER_INCLUDED_
Definition stack_ptr_decl.h:32
Representation for an element in the DOM.
Definition dom.h:47
bool hasAttribute(const std::string &name) const
DOMElement createChild(const std::string &name)
DOMElement getChild(const std::string &name) const
DOMAttributes getAttributes() const
DOMElement createChildBefore(const std::string &name, const DOMElement &before)
DOMElementList getChildren() const
bool removeChild(const std::string &name)
bool sortNodes(const std::string &query, SortingOrder order, std::size_t number_of_nodes)
std::string getAttribute(const std::string &name, const std::string &def_value=std::string()) const
std::string getPath() const
bool sortNodes(const std::string &query, SortingOrder order)
bool findNode(const std::string &query, DOMElement &element_ptr) const
std::string getData() const
DOMElement(const DOMElement &element)
friend bool operator==(const DOMElement &lhs, const DOMElement &rhs)
bool setName(const std::string &name)
bool eraseAttribute(const std::string &name)
bool findNodes(const std::string &query, DOMElementList &elements) const
std::string getName() const
bool setAttribute(const std::string &name, const std::string &strValue)
bool sortNodes(const std::string &query, const std::string &attribute, SortingOrder order, std::size_t number_of_nodes)
bool setData(const std::string &data)
std::size_t sortNodes(const std::string &query, const std::string &attribute, SortingOrder order)
DOMElement & operator=(const DOMElement &element)
DOMElement getParent() const
DOMException(const std::string &what)
XML parser to read and write standard XML files.
Definition dom.h:318
std::string getLastError() const
std::string toString() const
DOMElement getRoot() const
bool save(const std::string &file_path) const
DOM & operator=(const DOM &dom)
bool load(const std::string &file_path)
DOM(const DOM &dom)
bool findNodes(const std::string &query, DOMElementList &elements) const
bool isNull() const
bool fromString(const std::string &xml)
bool findNode(const std::string &query, DOMElement &element_ptr) const
Serves as component for handling XML.
Definition xml.h:20
bool operator==(const DOM &lhs, const DOM &rhs)
bool operator!=(const DOMElement &lhs, const DOMElement &rhs)
std::map< std::string, std::string > DOMAttributes
Type alias for DOM attributes.
Definition dom.h:44
std::list< DOMElement > DOMElementList
Tyoe alias for DOMElement lists.
Definition dom.h:42
Serves as the root component, with common functionality documented in core functionality.
Definition base.h:24
SortingOrder
Flags for functions that need to sort elements.
Definition enums.h:23