dom_node.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 "../api_core.h"
33 #include <memory>
34 #include "dom_string.h"
35 
36 namespace clan
37 {
40 
41 class DomElement;
42 class DomAttr;
43 class DomText;
44 class DomCDATASection;
45 class DomEntityReference;
46 class DomEntity;
47 class DomProcessingInstruction;
48 class DomComment;
49 class DomDocument;
50 class DomDocumentType;
51 class DomDocumentFragment;
52 class DomNotation;
53 class DomNodeList;
54 class DomNamedNodeMap;
55 class DomNode_Impl;
56 
71 class CL_API_CORE DomNode
72 {
75 
76 public:
77  DomNode();
78 
82  DomNode(const DomNode &copy);
83 
84  ~DomNode();
85 
89 
90 public:
92  enum NodeType
93  {
94  NULL_NODE = 0,
95  ELEMENT_NODE = 1,
96  ATTRIBUTE_NODE = 2,
97  TEXT_NODE = 3,
98  CDATA_SECTION_NODE = 4,
99  ENTITY_REFERENCE_NODE = 5,
100  ENTITY_NODE = 6,
101  PROCESSING_INSTRUCTION_NODE = 7,
102  COMMENT_NODE = 8,
103  DOCUMENT_NODE = 9,
104  DOCUMENT_TYPE_NODE = 10,
105  DOCUMENT_FRAGMENT_NODE = 11,
106  NOTATION_NODE = 12
107  };
108 
110 
125  DomString get_node_name() const;
126 
128  DomString get_namespace_uri() const;
129 
131 
134  DomString get_prefix() const;
135 
137 
144  void set_prefix(const DomString &prefix);
145 
147 
150  DomString get_local_name() const;
151 
153 
168  DomString get_node_value() const;
169 
171  void set_node_value(const DomString &value);
172 
174  unsigned short get_node_type() const;
175 
177 
180  DomNode get_parent_node() const;
181 
183 
189  DomNodeList get_child_nodes() const;
190 
192 
193  DomNode get_first_child() const;
194 
196 
197  DomNode get_last_child() const;
198 
200 
201  DomNode get_previous_sibling() const;
202 
204 
205  DomNode get_next_sibling() const;
206 
208  DomNamedNodeMap get_attributes() const;
209 
211 
212  DomDocument get_owner_document() const;
213 
215  bool is_null() const;
216 
218  bool is_element() const;
219 
221  bool is_attr() const;
222 
224  bool is_text() const;
225 
227  bool is_cdata_section() const;
228 
230  bool is_entity_reference() const;
231 
233  bool is_entity() const;
234 
236  bool is_processing_instruction() const;
237 
239  bool is_comment() const;
240 
242  bool is_document() const;
243 
245  bool is_document_type() const;
246 
248  bool is_document_fragment() const;
249 
251  bool is_notation() const;
252 
254  bool is_supported(const DomString &feature, const DomString &version) const;
255 
257  bool has_attributes() const;
258 
260  bool has_child_nodes() const;
261 
265 
266 public:
268 
271  DomNode &operator =(const DomNode &copy);
272 
274  bool operator ==(const DomNode &other) const;
275 
277  bool operator !=(const DomNode &other) const;
278 
280 
290  void normalize();
291 
293 
299  DomNode insert_before(DomNode &new_child, DomNode &ref_child);
300 
302 
306  DomNode replace_child(DomNode &new_child, DomNode &old_child);
307 
309  DomNode remove_child(DomNode &old_child);
310 
312 
313  DomNode append_child(DomNode new_child);
314 
316 
323  DomNode clone_node(bool deep) const;
324 
326 
327  DomElement to_element() const;
328 
330 
331  DomAttr to_attr() const;
332 
334 
335  DomText to_text() const;
336 
338 
339  DomCDATASection to_cdata_section() const;
340 
342 
343  DomEntityReference to_entity_reference() const;
344 
346 
347  DomEntity to_entity() const;
348 
350 
351  DomProcessingInstruction to_processing_instruction() const;
352 
354 
355  DomComment to_comment() const;
356 
358 
359  DomDocument to_document() const;
360 
362 
363  DomDocumentType to_document_type() const;
364 
366 
367  DomDocumentFragment to_document_fragment() const;
368 
370 
371  DomNotation to_notation() const;
372 
374 
375  DomNode named_item(const DomString &name) const;
376 
378  DomNode named_item_ns(
379  const DomString &namespace_uri,
380  const DomString &local_name) const;
381 
383  DomString find_namespace_uri(const DomString &qualified_name) const;
384 
386  DomString find_prefix(const DomString &namespace_uri) const;
387 
389  std::vector<DomNode> select_nodes(const DomString &xpath_expression) const;
390 
392  DomNode select_node(const DomString &xpath_expression) const;
393 
395  std::string select_string(const DomString &xpath_expression) const;
396 
398  int select_int(const DomString &xpath_expression) const;
399 
401  float select_float(const DomString &xpath_expression) const;
402 
404  bool select_bool(const DomString &xpath_expression) const;
405 
409 
410 protected:
411 
416  DomNode(DomDocument doc, unsigned short node_type);
417 
421  DomNode(const std::shared_ptr<DomNode_Impl> &impl);
422 
423  std::shared_ptr<DomNode_Impl> impl;
424 
425  friend class DomDocument;
426 
427  friend class DomNamedNodeMap;
429 };
430 
431 }
432 
DOM Attribute class.
Definition: dom_attr.h:67
DOM Comment class.
Definition: dom_comment.h:45
DOM Node List class.
Definition: dom_node_list.h:51
DOM Document Type class.
Definition: dom_document_type.h:51
DOM CDATA Section.
Definition: dom_cdata_section.h:55
DOM Entity class.
Definition: dom_entity.h:46
NodeType
An integer indicating which type of node this is.
Definition: dom_node.h:92
std::string DomString
Definition: dom_string.h:37
std::shared_ptr< DomNode_Impl > impl
Definition: dom_node.h:423
DOM Document class.
Definition: dom_document.h:65
DOM Entity Reference class.
Definition: dom_entity_reference.h:52
DOM Node class.
Definition: dom_node.h:71
DOM Element class.
Definition: dom_element.h:60
DOM Text class.
Definition: dom_text.h:55
DOM Notation class.
Definition: dom_notation.h:49
DOM Document Fragment class.
Definition: dom_document_fragment.h:71
DOM Named Node Map class.
Definition: dom_named_node_map.h:52
DOM Processing Instruction class.
Definition: dom_processing_instruction.h:44