dom_element.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 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 {
63
64 public:
66 DomElement();
67
68 DomElement(
69 DomDocument &doc,
70 const DomString &tag_name,
71 const DomString &namespace_uri = DomString());
72
76 DomElement(const std::shared_ptr<DomNode_Impl> &impl);
77
78 ~DomElement();
79
83
84 public:
86 DomString get_tag_name() const;
87
91
92 public:
94 bool has_attribute(const DomString &name) const;
95
97 bool has_attribute_ns(
98 const DomString &namespace_uri,
99 const DomString &local_name) const;
100
102 DomString get_attribute(const DomString &name) const;
103
110 DomString get_attribute(const DomString &name, const DomString &default_value) const;
111
113 DomString get_attribute_ns(
114 const DomString &namespace_uri,
115 const DomString &local_name) const;
116
117 DomString get_attribute_ns(
118 const DomString &namespace_uri,
119 const DomString &local_name,
120 const DomString &default_value) const;
121
123
131 void set_attribute(const DomString &name, const DomString &value);
132
133 void set_attribute_ns(
134 const DomString &namespace_uri,
135 const DomString &qualified_name,
136 const DomString &value);
137
139
140 void remove_attribute(const DomString &name);
141
142 void remove_attribute_ns(
143 const DomString &namespace_uri,
144 const DomString &local_name);
145
151 DomAttr get_attribute_node(const DomString &name) const;
152
153 DomAttr get_attribute_node_ns(
154 const DomString &namespace_uri,
155 const DomString &local_name) const;
156
162 DomAttr set_attribute_node(const DomAttr &attr);
163
169 DomAttr set_attribute_node_ns(const DomAttr &attr);
170
172
174 DomNodeList get_elements_by_tag_name(const DomString &name);
175
176 DomNodeList get_elements_by_tag_name_ns(
177 const DomString &namespace_uri,
178 const DomString &local_name);
179
181 std::string get_text() const;
182
184
185 DomString get_child_string(const DomString &name, const DomString &default_value = DomString()) const;
186
188
189 DomString get_child_string_ns(const DomString &namespace_uri, const DomString &local_name, const DomString &default_value = DomString()) const;
190
192
193 int get_child_int(const DomString &name, int default_value = 0) const;
194
196
197 int get_child_int_ns(const DomString &namespace_uri, const DomString &local_name, int default_value = 0) const;
198
200
201 bool get_child_bool(const DomString &name, bool default_value = false) const;
202
204
205 bool get_child_bool_ns(const DomString &namespace_uri, const DomString &local_name, bool default_value = false) const;
206
208
209 void set_child_string(const DomString &name, const DomString &value);
210
212
213 void set_child_string_ns(const DomString &namespace_uri, const DomString &qualified_name, const DomString &value);
214
216
217 void set_child_int(const DomString &name, int value);
218
220
221 void set_child_int_ns(const DomString &namespace_uri, const DomString &qualified_name, int value);
222
224
225 void set_child_bool(const DomString &name, bool value);
226
228
229 void set_child_bool_ns(const DomString &namespace_uri, const DomString &qualified_name, bool value);
230
232 DomElement get_first_child_element() const;
233
235 DomElement get_next_sibling_element() const;
236
238 int get_attribute_int(const DomString &name, int default_value = 0) const;
239
241 int get_attribute_int_ns(const DomString &namespace_uri, const DomString &local_name, int default_value = 0) const;
242
244 bool get_attribute_bool(const DomString &name, bool default_value = false) const;
245
247 bool get_attribute_bool_ns(const DomString &namespace_uri, const DomString &local_name, bool default_value = false) const;
248
250 float get_attribute_float(const DomString &name, float default_value = 0.0f) const;
251
253 float get_attribute_float_ns(const DomString &namespace_uri, const DomString &local_name, float default_value = 0.0f) const;
254
256 void set_attribute_int(const DomString &name, int value);
257
259 void set_attribute_int_ns(const DomString &namespace_uri, const DomString &qualified_name, int value);
260
262 void set_attribute_bool(const DomString &name, bool value);
263
265 void set_attribute_bool_ns(const DomString &namespace_uri, const DomString &qualified_name, bool value);
266
268 void set_attribute_float(const DomString &name, float value, int num_decimal_places = 6);
269
271 void set_attribute_float_ns(const DomString &namespace_uri, const DomString &qualified_name, float value, int num_decimal_places = 6);
273 };
274
275 }
276
clan::DomElement::set_attribute_int_ns
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...
clan::DomAttr
DOM Attribute class.
Definition: dom_attr.h:66
clan
Definition: clanapp.h:35
clan::DomElement::get_attribute_bool_ns
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.
clan::DomElement::get_child_string_ns
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. ...
clan::DomElement::remove_attribute
void remove_attribute(const DomString &name)
Removes an attribute by name.
clan::DomNodeList
DOM Node List class.
Definition: dom_node_list.h:50
clan::DomElement::set_child_int
void set_child_int(const DomString &name, int value)
Sets the child node with the specified tag name to the given integer value.
clan::DomElement::get_child_bool
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.
clan::DomElement::get_attribute_float_ns
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...
clan::DomElement::get_attribute_int_ns
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.
clan::DomElement::get_elements_by_tag_name_ns
DomNodeList get_elements_by_tag_name_ns(const DomString &namespace_uri, const DomString &local_name)
clan::DomElement::set_child_string
void set_child_string(const DomString &name, const DomString &value)
Sets the child node with the specified tag name to the given text value.
clan::DomElement::get_first_child_element
DomElement get_first_child_element() const
Returns the first child node that is an element node.
clan::DomElement::get_attribute
DomString get_attribute(const DomString &name) const
Returns the specified attribute.
clan::DomElement::set_child_bool
void set_child_bool(const DomString &name, bool value)
Sets the child node with the specified tag name to the given boolean value.
clan::DomElement::set_attribute_node_ns
DomAttr set_attribute_node_ns(const DomAttr &attr)
Set attribute node ns.
clan::DomElement::get_attribute_node_ns
DomAttr get_attribute_node_ns(const DomString &namespace_uri, const DomString &local_name) const
clan::DomElement::has_attribute_ns
bool has_attribute_ns(const DomString &namespace_uri, const DomString &local_name) const
Returns true if the element has the specified attribute.
clan::DomElement::set_child_string_ns
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...
clan::DomElement::set_attribute_float
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.
clan::DomElement::remove_attribute_ns
void remove_attribute_ns(const DomString &namespace_uri, const DomString &local_name)
clan::DomString
std::string DomString
Definition: dom_string.h:37
clan::DomNode::impl
std::shared_ptr< DomNode_Impl > impl
Definition: dom_node.h:422
clan::DomDocument
DOM Document class.
Definition: dom_document.h:64
clan::StyleTokenType::string
@ keyword
clan::DomNode
DOM Node class.
Definition: dom_node.h:70
clan::DomElement::~DomElement
~DomElement()
clan::DomElement::set_child_int_ns
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...
clan::Key::f
clan::DomElement
DOM Element class.
Definition: dom_element.h:59
clan::DomElement::has_attribute
bool has_attribute(const DomString &name) const
Returns true if the element has the specified attribute.
clan::DomElement::set_attribute_int
void set_attribute_int(const DomString &name, int value)
Sets the attribute node with the specified tag name to the given integer value.
clan::DomElement::set_attribute
void set_attribute(const DomString &name, const DomString &value)
Adds a new attribute.
clan::DomElement::get_next_sibling_element
DomElement get_next_sibling_element() const
Returns the next sibling node that is an element node.
clan::DomElement::get_child_int_ns
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.
clan::DomElement::get_child_bool_ns
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.
clan::DomElement::get_tag_name
DomString get_tag_name() const
Returns the name of the element.
clan::DomElement::get_attribute_bool
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.
clan::DomElement::get_attribute_ns
DomString get_attribute_ns(const DomString &namespace_uri, const DomString &local_name) const
Returns the specified attribute.
clan::DomElement::set_attribute_float_ns
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...
clan::DomElement::get_attribute_float
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.
clan::DomElement::get_elements_by_tag_name
DomNodeList get_elements_by_tag_name(const DomString &name)
Returns a NodeList of all descendant elements with a given tag name.
clan::DomElement::get_attribute_int
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.
clan::DomElement::set_attribute_ns
void set_attribute_ns(const DomString &namespace_uri, const DomString &qualified_name, const DomString &value)
clan::DomElement::DomElement
DomElement()
Constructs a DOM Element handle.
clan::DomElement::set_attribute_node
DomAttr set_attribute_node(const DomAttr &attr)
Set attribute node.
clan::DomElement::get_text
std::string get_text() const
Returns the text of all child Text nodes appended together.
clan::DomElement::get_attribute_node
DomAttr get_attribute_node(const DomString &name) const
Get attribute node.
clan::DomElement::get_child_string
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.
clan::DomElement::set_child_bool_ns
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...
clan::DomElement::set_attribute_bool
void set_attribute_bool(const DomString &name, bool value)
Sets the attribute node with the specified tag name to the given boolean value.
clan::DomElement::set_attribute_bool_ns
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...
clan::DomElement::get_child_int
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.