Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
XmlNode.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* XmlNode.h (C) 2000-2023 */
9/* */
10/* Any node in a DOM tree. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_XMLNODE_H
13#define ARCANE_CORE_XMLNODE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/String.h"
18#include "arcane/core/Dom.h"
19
20#include <iterator>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31class IRessourceMng;
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
36class XmlNodeIterator;
38class XmlNodeList;
39
50class ARCANE_CORE_EXPORT XmlNode
51{
52 public:
53
55 typedef XmlNode value_type;
63 typedef const value_type* const_pointer;
71 typedef int difference_type;
72
77
78 public:
79
111
112 public:
113
114 XmlNode(IRessourceMng* m, const dom::Node& node)
115 : m_rm(m)
116 , m_node(node)
117 {}
118 //TODO: to be removed
119 explicit XmlNode(IRessourceMng* m)
120 : m_rm(m)
121 , m_node()
122 {}
123 XmlNode()
124 : m_rm(nullptr)
125 , m_node()
126 {}
127
128 public:
129
131 inline iterator begin();
133 inline iterator end();
135 inline const_iterator begin() const;
137 inline const_iterator end() const;
138
139 public:
140
142 eType type() const;
143
145 String name() const;
146
150 String xpathFullName() const;
151
153 bool isNamed(const String& name) const;
154
162 String value() const;
163
169 Integer valueAsInteger(bool throw_exception = false) const;
170
176 Int64 valueAsInt64(bool throw_exception = false) const;
177
185 bool valueAsBoolean(bool throw_exception = false) const;
186
191 Real valueAsReal(bool throw_exception = false) const;
192
199 void setValue(const String& value);
200
206 String attrValue(const String& name, bool throw_exception = false) const;
207
209 void setAttrValue(const String& name, const String& value);
210
217 XmlNode attr(const String& name, bool throw_exception = false) const;
218
224 XmlNode forceAttr(const String& name);
225
230 void removeAttr(const String& name) const;
231
236 XmlNode documentElement() const;
237
242 XmlNode ownerElement() const;
243
245 void clear();
246
253 XmlNode child(const String& name) const;
254
261 XmlNode expectedChild(const String& name) const;
262
264 XmlNodeList children(const String& name) const;
265
267 XmlNodeList children() const;
268
270 XmlNode parent() const { return XmlNode(m_rm, m_node.parentNode()); }
271
276 void append(const XmlNode& child_node) { m_node.appendChild(child_node.domNode()); }
278 void remove(const XmlNode& child_node);
280 void replace(const XmlNode& new_node, XmlNode& ref_node);
282 void remove();
284 XmlNode front() const { return XmlNode(m_rm, m_node.firstChild()); }
286 XmlNode last() const { return XmlNode(m_rm, m_node.lastChild()); }
288 XmlNode next() const { return XmlNode(m_rm, m_node.nextSibling()); }
290 XmlNode prev() const { return XmlNode(m_rm, m_node.previousSibling()); }
292 XmlNode nextWithName(const String& name) const;
294 XmlNode prevWithName(const String& name) const;
296 XmlNode nextSameType() const;
298 XmlNode prevSameType() const;
299 void operator++() { m_node = m_node.nextSibling(); }
300 void operator--() { m_node = m_node.previousSibling(); }
301
303 bool null() const { return m_node._null(); }
304 bool operator!() const { return null(); }
305
307 dom::Node domNode() const { return m_node; }
309 void assignDomNode(const dom::Node& node);
310
320 XmlNode insertAfter(const XmlNode& new_child, const XmlNode& ref_node);
321
326 XmlNode childWithAttr(const String& elem_name, const String& attr_name,
327 const String& attr_value) const;
332 XmlNode childWithNameAttr(const String& elem_name,
333 const String& attr_value) const;
334
339 XmlNode xpathNode(const String& xpath_expr) const;
340
353 XmlNode createNode(eType type, const String& name, const String& value);
354
365 XmlNode createNode(eType type, const String& name_or_value);
366
372 XmlNode createText(const String& value);
373
374 XmlNode createElement(const String& name);
375
376 XmlNode createAndAppendElement(const String& name);
377
378 XmlNode createAndAppendElement(const String& name, const String& value);
379
380 XmlNode ownerDocument() const { return XmlNode(m_rm, m_node.ownerDocument()); }
381
382 IRessourceMng* rm() const { return m_rm; }
383
384 private:
385
386 IRessourceMng* m_rm;
387 dom::Node m_node;
388
389 protected:
390
391 String _value() const;
392 XmlNode _build(const dom::Node& node) const;
393 XmlNode _nullNode() const;
394 void _setNode(const dom::Node& n) { m_node = n; }
395 inline void _throwBadConvert(const char* type_name, const String& value) const;
396};
397
398/*---------------------------------------------------------------------------*/
399/*---------------------------------------------------------------------------*/
400
404class ARCANE_CORE_EXPORT XmlElement
405: public XmlNode
406{
407 public:
408
413 XmlElement(XmlNode& parent, const String& name, const String& value);
418 XmlElement(XmlNode& parent, const String& name);
419};
420
421/*---------------------------------------------------------------------------*/
422/*---------------------------------------------------------------------------*/
423
424inline bool
425operator==(const XmlNode& n1, const XmlNode& n2)
426{
427 return n1.domNode() == n2.domNode();
428}
429
430inline bool
431operator!=(const XmlNode& n1, const XmlNode& n2)
432{
433 return n1.domNode() != n2.domNode();
434}
435
436/*---------------------------------------------------------------------------*/
437/*---------------------------------------------------------------------------*/
438
439} // namespace Arcane
440
441/*---------------------------------------------------------------------------*/
442/*---------------------------------------------------------------------------*/
443
444#endif
Interface of a resource manager.
Iterator intervalThis class manages an iterator pair allowing modification of the elements of the con...
XmlElement(XmlNode &parent, const String &name, const String &value)
Creates a child element of parent. The created element has the name name and the value value....
Definition XmlNode.cc:691
List of nodes of a DOM tree.
Definition XmlNodeList.h:36
Node of a DOM tree.
Definition XmlNode.h:51
int difference_type
Type of a distance between iterator elements in the array.
Definition XmlNode.h:71
Integer size_type
Type indexing the array.
Definition XmlNode.h:69
XmlNode value_type
Type of the elements in the array.
Definition XmlNode.h:55
value_type & reference
Type reference of an element in the array.
Definition XmlNode.h:65
const value_type & const_reference
Type constant reference of an element in the array.
Definition XmlNode.h:67
value_type * pointer
Type pointer of an element in the array.
Definition XmlNode.h:61
const value_type * const_pointer
Type constant pointer of an element in the array.
Definition XmlNode.h:63
XmlNodeIterator iterator
Type of the iterator over an element in the array.
Definition XmlNode.h:57
XmlNode prev() const
Previous node (previousSibling()).
Definition XmlNode.h:290
XmlNodeConstIterator const_iterator
Type of the constant iterator over an element in the array.
Definition XmlNode.h:59
void append(const XmlNode &child_node)
Adds child_node as a child of this node.
Definition XmlNode.h:276
String value() const
Node value.
Definition XmlNode.cc:208
IterT< XmlNode > iter
Type of an iterator over the entire array.
Definition XmlNode.h:74
XmlNode front() const
First child.
Definition XmlNode.h:284
bool null() const
True if the node is null.
Definition XmlNode.h:303
XmlNode next() const
Next node (nextSibling()).
Definition XmlNode.h:288
eType
NodeType An integer indicating which type of node this is.
Definition XmlNode.h:85
@ TEXT
The node is a Text node.
Definition XmlNode.h:91
@ ATTRIBUTE
The node is an Attr.
Definition XmlNode.h:89
@ ENTITY
The node is an Entity.
Definition XmlNode.h:97
@ ELEMENT
The node is an Element.
Definition XmlNode.h:87
@ DOCUMENT_TYPE
The node is a DocumentType.
Definition XmlNode.h:105
@ ENTITY_REFERENCE
The node is an EntityReference.
Definition XmlNode.h:95
@ COMMENT
The node is a Comment.
Definition XmlNode.h:101
@ NOTATION
The node is a Notation.
Definition XmlNode.h:109
@ CDATA_SECTION
The node is a CDATASection.
Definition XmlNode.h:93
@ PROCESSING_INSTRUCTION
The node is a ProcessingInstruction.
Definition XmlNode.h:99
@ DOCUMENT
The node is a Document.
Definition XmlNode.h:103
@ DOCUMENT_FRAGMENT
The node is a DocumentFragment.
Definition XmlNode.h:107
ConstIterT< XmlNode > const_iter
Type of a constant iterator over the entire array.
Definition XmlNode.h:76
XmlNode parent() const
Parent of this node (null if none).
Definition XmlNode.h:270
String name() const
Node name.
Definition XmlNode.cc:141
XmlNode last() const
Last child.
Definition XmlNode.h:286
dom::Node domNode() const
Definition XmlNode.h:307
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.