dom_element.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 
30 #pragma once
31 
32 #include "dom_node.h"
33 
34 namespace clan
35 {
38 
59  class DomElement : public DomNode
60  {
61  public:
63  DomElement();
64 
65  DomElement(
66  DomDocument &doc,
67  const DomString &tag_name,
68  const DomString &namespace_uri = DomString());
69 
73  DomElement(const std::shared_ptr<DomNode_Impl> &impl);
74 
75  ~DomElement();
76 
78  DomString get_tag_name() const;
79 
81  bool has_attribute(const DomString &name) const;
82 
84  bool has_attribute_ns(
85  const DomString &namespace_uri,
86  const DomString &local_name) const;
87 
89  DomString get_attribute(const DomString &name) const;
90 
97  DomString get_attribute(const DomString &name, const DomString &default_value) const;
98 
101  const DomString &namespace_uri,
102  const DomString &local_name) const;
103 
105  const DomString &namespace_uri,
106  const DomString &local_name,
107  const DomString &default_value) const;
108 
110 
118  void set_attribute(const DomString &name, const DomString &value);
119 
120  void set_attribute_ns(
121  const DomString &namespace_uri,
122  const DomString &qualified_name,
123  const DomString &value);
124 
126 
127  void remove_attribute(const DomString &name);
128 
129  void remove_attribute_ns(
130  const DomString &namespace_uri,
131  const DomString &local_name);
132 
138  DomAttr get_attribute_node(const DomString &name) const;
139 
141  const DomString &namespace_uri,
142  const DomString &local_name) const;
143 
149  DomAttr set_attribute_node(const DomAttr &attr);
150 
157 
159 
162 
164  const DomString &namespace_uri,
165  const DomString &local_name);
166 
168  std::string get_text() const;
169 
171 
172  DomString get_child_string(const DomString &name, const DomString &default_value = DomString()) const;
173 
175 
176  DomString get_child_string_ns(const DomString &namespace_uri, const DomString &local_name, const DomString &default_value = DomString()) const;
177 
179 
180  int get_child_int(const DomString &name, int default_value = 0) const;
181 
183 
184  int get_child_int_ns(const DomString &namespace_uri, const DomString &local_name, int default_value = 0) const;
185 
187 
188  bool get_child_bool(const DomString &name, bool default_value = false) const;
189 
191 
192  bool get_child_bool_ns(const DomString &namespace_uri, const DomString &local_name, bool default_value = false) const;
193 
195 
196  void set_child_string(const DomString &name, const DomString &value);
197 
199 
200  void set_child_string_ns(const DomString &namespace_uri, const DomString &qualified_name, const DomString &value);
201 
203 
204  void set_child_int(const DomString &name, int value);
205 
207 
208  void set_child_int_ns(const DomString &namespace_uri, const DomString &qualified_name, int value);
209 
211 
212  void set_child_bool(const DomString &name, bool value);
213 
215 
216  void set_child_bool_ns(const DomString &namespace_uri, const DomString &qualified_name, bool value);
217 
220 
223 
225  int get_attribute_int(const DomString &name, int default_value = 0) const;
226 
228  int get_attribute_int_ns(const DomString &namespace_uri, const DomString &local_name, int default_value = 0) const;
229 
231  bool get_attribute_bool(const DomString &name, bool default_value = false) const;
232 
234  bool get_attribute_bool_ns(const DomString &namespace_uri, const DomString &local_name, bool default_value = false) const;
235 
237  float get_attribute_float(const DomString &name, float default_value = 0.0f) const;
238 
240  float get_attribute_float_ns(const DomString &namespace_uri, const DomString &local_name, float default_value = 0.0f) const;
241 
243  void set_attribute_int(const DomString &name, int value);
244 
246  void set_attribute_int_ns(const DomString &namespace_uri, const DomString &qualified_name, int value);
247 
249  void set_attribute_bool(const DomString &name, bool value);
250 
252  void set_attribute_bool_ns(const DomString &namespace_uri, const DomString &qualified_name, bool value);
253 
255  void set_attribute_float(const DomString &name, float value, int num_decimal_places = 6);
256 
258  void set_attribute_float_ns(const DomString &namespace_uri, const DomString &qualified_name, float value, int num_decimal_places = 6);
259  };
260 
262 }
bool get_child_bool_ns(const DomString &namespace_uri, const DomString &local_name, bool default_value=false) const
Returns the boolean value of the child node with the given local name and namespace.
DomString get_child_string_ns(const DomString &namespace_uri, const DomString &local_name, const DomString &default_value=DomString()) const
Returns the text value of the child node with the given local name and namespace. ...
void set_child_bool(const DomString &name, bool value)
Sets the child node with the specified tag name to the given boolean value.
DOM Attribute class.
Definition: dom_attr.h:66
Definition: clanapp.h:35
DomString get_tag_name() const
Returns the name of the element.
DOM Node List class.
Definition: dom_node_list.h:50
std::string DomString
Definition: dom_string.h:37
std::string get_text() const
Returns the text of all child Text nodes appended together.
DomString get_child_string(const DomString &name, const DomString &default_value=DomString()) const
Returns the text value of the child node with the given tag name.
bool has_attribute_ns(const DomString &namespace_uri, const DomString &local_name) const
Returns true if the element has the specified attribute.
float get_attribute_float_ns(const DomString &namespace_uri, const DomString &local_name, float default_value=0.0f) const
Returns the floating-point value of the attribute node with the given local name and namespace...
void set_child_int(const DomString &name, int value)
Sets the child node with the specified tag name to the given integer value.
void set_child_string_ns(const DomString &namespace_uri, const DomString &qualified_name, const DomString &value)
Sets the child node with the specified qualified name and namespace to the given text value...
DomAttr set_attribute_node_ns(const DomAttr &attr)
Set attribute node ns.
void set_child_string(const DomString &name, const DomString &value)
Sets the child node with the specified tag name to the given text value.
void set_attribute_ns(const DomString &namespace_uri, const DomString &qualified_name, const DomString &value)
DOM Document class.
Definition: dom_document.h:64
void set_attribute_int_ns(const DomString &namespace_uri, const DomString &qualified_name, int value)
Sets the attribute node with the specified qualified name and namespace to the given integer value...
std::shared_ptr< DomNode_Impl > impl
Definition: dom_node.h:396
DOM Node class.
Definition: dom_node.h:70
bool get_child_bool(const DomString &name, bool default_value=false) const
Returns the boolean value of the child node with the given tag name.
DomNodeList get_elements_by_tag_name(const DomString &name)
Returns a NodeList of all descendant elements with a given tag name.
DomString get_attribute_ns(const DomString &namespace_uri, const DomString &local_name) const
Returns the specified attribute.
void set_attribute_float(const DomString &name, float value, int num_decimal_places=6)
Sets the attribute node with the specified tag name to the given floating-point value.
int get_child_int(const DomString &name, int default_value=0) const
Returns the integer value of the child node with the given tag name.
DOM Element class.
Definition: dom_element.h:59
DomString get_attribute(const DomString &name) const
Returns the specified attribute.
void remove_attribute(const DomString &name)
Removes an attribute by name.
void set_attribute_bool(const DomString &name, bool value)
Sets the attribute node with the specified tag name to the given boolean value.
DomAttr get_attribute_node_ns(const DomString &namespace_uri, const DomString &local_name) const
bool get_attribute_bool(const DomString &name, bool default_value=false) const
Returns the boolean value of the attribute node with the given tag name.
void set_child_bool_ns(const DomString &namespace_uri, const DomString &qualified_name, bool value)
Sets the child node with the specified qualified name and namespace to the given boolean value...
bool has_attribute(const DomString &name) const
Returns true if the element has the specified attribute.
DomAttr get_attribute_node(const DomString &name) const
Get attribute node.
void set_attribute_bool_ns(const DomString &namespace_uri, const DomString &qualified_name, bool value)
Sets the attribute node with the specified qualified name and namespace to the given boolean value...
float get_attribute_float(const DomString &name, float default_value=0.0f) const
Returns the floating-point value of the attribute node with the given tag name.
DomElement get_first_child_element() const
Returns the first child node that is an element node.
void remove_attribute_ns(const DomString &namespace_uri, const DomString &local_name)
void set_attribute_int(const DomString &name, int value)
Sets the attribute node with the specified tag name to the given integer value.
void set_attribute_float_ns(const DomString &namespace_uri, const DomString &qualified_name, float value, int num_decimal_places=6)
Sets the attribute node with the specified qualified name and namespace to the given floating-point v...
DomAttr set_attribute_node(const DomAttr &attr)
Set attribute node.
DomNodeList get_elements_by_tag_name_ns(const DomString &namespace_uri, const DomString &local_name)
DomElement()
Constructs a DOM Element handle.
int get_attribute_int_ns(const DomString &namespace_uri, const DomString &local_name, int default_value=0) const
Returns the integer value of the attribute node with the given local name and namespace.
DomElement get_next_sibling_element() const
Returns the next sibling node that is an element node.
int get_child_int_ns(const DomString &namespace_uri, const DomString &local_name, int default_value=0) const
Returns the integer value of the child node with the given local name and namespace.
int get_attribute_int(const DomString &name, int default_value=0) const
Returns the integer value of the attribute node with the given tag name.
void set_child_int_ns(const DomString &namespace_uri, const DomString &qualified_name, int value)
Sets the child node with the specified qualified name and namespace to the given integer value...
bool get_attribute_bool_ns(const DomString &namespace_uri, const DomString &local_name, bool default_value=false) const
Returns the boolean value of the attribute node with the given local name and namespace.
void set_attribute(const DomString &name, const DomString &value)
Adds a new attribute.