14#include "arcane/core/XmlNode.h"
16#include "arcane/utils/StringBuilder.h"
17#include "arcane/utils/NotImplementedException.h"
18#include "arcane/utils/Iterator.h"
19#include "arcane/utils/ValueConvert.h"
20#include "arcane/utils/Iostream.h"
21#include "arcane/utils/TraceInfo.h"
22#include "arcane/utils/FatalErrorException.h"
24#include "arcane/core/XmlException.h"
25#include "arcane/core/XmlNodeList.h"
26#include "arcane/core/XmlNodeIterator.h"
27#include "arcane/core/DomUtils.h"
44 XmlNodeSameName(
const String& name)
50 bool operator()(
const XmlNode& node)
52 return node.
name() == m_name;
92 XmlNode c =
child(child_name);
134 return static_cast<eType>(m_node.nodeType());
145 return String(m_node.nodeName());
170 for (XmlNode i = p.
front(); i != (*
this); ++i)
171 if (i.isNamed(
name()))
173 if (nb_occurence > 1) {
175 full_name += nb_occurence;
201 return m_node.nodeName() ==
name;
224 domutils::textContent(m_node, v);
237 if (s.
null() && throw_exception) {
263 XmlNode attr_node(m_rm, elem.getAttributeNode(
name));
264 if (throw_exception && attr_node.
null()) {
282 attr = elem.ownerDocument().createAttribute(
name);
285 return XmlNode(m_rm,
attr);
295 elem.removeAttribute(
name);
323 parent.removeChild(m_node);
330remove(
const XmlNode& child_node)
400replace(
const XmlNode& new_node, XmlNode& ref_node)
402 if (m_node._null() || new_node.
null() || ref_node.
null())
411_throwBadConvert(
const char* type_name,
const String& value)
const
432 " Valid values are 'true', 'false', '0' (zero) or '1'.",
447 if (builtInGetValue(v,
value))
449 _throwBadConvert(
"Integer",
value);
463 if (builtInGetValue(v,
value))
465 _throwBadConvert(
"Int64",
value);
479 if (builtInGetValue(v,
value))
481 _throwBadConvert(
"Real",
value);
490 const String& attr_value)
const
496 if (!i->isNamed(elem_name))
498 name = i->attrValue(attr_name);
499 if (
name == attr_value)
502 return XmlNode(m_rm);
520 return XmlNode(m_rm, domutils::nodeFromXPath(m_node, xpath_expr));
530 return domutils::textContent(m_node);
531 return String(m_node.nodeValue());
547insertAfter(
const XmlNode& new_child,
const XmlNode& ref_node)
549 if (new_child.
null())
551 XmlNode
next = ref_node;
557 m_node.insertBefore(new_child.
domNode(),
next.domNode());
570 return _build(doc.documentElement());
582 return _build(
attr.ownerElement());
589createElement(
const String& name)
598createAndAppendElement(
const String& name,
const String& value)
609createAndAppendElement(
const String& name)
624 doc = m_node.ownerDocument();
625 XmlNode ret_node(m_rm);
626 String nov = name_or_value;
636 "createNode() not implemented for node type {0}", (
int)
type);
658 doc = m_node.ownerDocument();
659 XmlNode ret_node(m_rm);
670 "createNode() not implemented for node type {0}", (
int)
type);
704 _setNode(
parent.createAndAppendElement(
name).domNode());
714XmlNodeNameIterator(
const XmlNode& from,
const String& ref_name)
717, m_ref_name(ref_name)
719 _findNextValid(
true);
726XmlNodeNameIterator(
const XmlNode& from,
const char* ref_name)
729, m_ref_name(String(ref_name))
731 _findNextValid(
true);
737void XmlNodeNameIterator::
738_findNextValid(
bool is_init)
741 m_current = m_parent.front();
743 if (m_current.null())
747 while (!m_current.null()) {
748 if (m_current.isNamed(m_ref_name))
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
void add(ConstReferenceType val)
Adds element val to the end of the array.
Exception when a function is not implemented.
Unicode character string constructor.
StringBuilder & append(const String &str)
Appends str.
Unicode character string.
bool null() const
Returns true if the string is null.
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....
XML file related exceptions.
List of nodes of a DOM tree.
XmlNode attr(const String &name, bool throw_exception=false) const
Returns the attribute of name name.
XmlNode prevSameType() const
Returns the previous node of the same type.
String xpathFullName() const
XPath name of the node with its ancestors.
void setValue(const String &value)
Sets the node value.
void assignDomNode(const dom::Node &node)
XmlNode documentElement() const
Returns the document element.
void replace(const XmlNode &new_node, XmlNode &ref_node)
Replaces the child node ref_node with the node new_node.
Int64 valueAsInt64(bool throw_exception=false) const
Node value converted to 64-bit integer. 0 if conversion fails.
eType type() const
Node type.
iterator end()
Returns an iterator over the first element after the end of the array.
XmlNode insertAfter(const XmlNode &new_child, const XmlNode &ref_node)
Inserts a node. Inserts the node new_child after the node ref_node. If new_child is null,...
XmlNodeList children() const
Set of child nodes of this node.
void removeAttr(const String &name) const
Removes the attribute of name name from this node. If this node is not an element,...
XmlNode prev() const
Previous node (previousSibling()).
String attrValue(const String &name, bool throw_exception=false) const
Value of attribute name.
Real valueAsReal(bool throw_exception=false) const
Node value converted to real number. If conversion fails, if throw_exception is false returns 0....
XmlNode childWithNameAttr(const String &elem_name, const String &attr_value) const
Returns the child of this node having the name elem_name and an attribute of name "name" with value a...
XmlNode child(const String &name) const
Child node of this node with name name.
void clear()
Deletes all child nodes.
XmlNode forceAttr(const String &name)
Returns the attribute of name name. If no attribute with this name exists, an attribute with the null...
XmlNode xpathNode(const String &xpath_expr) const
Returns a node from an XPath expression.
void append(const XmlNode &child_node)
Adds child_node as a child of this node.
String value() const
Node value.
XmlNode front() const
First child.
XmlNode createText(const String &value)
Creates a text node.
bool null() const
True if the node is null.
XmlNode next() const
Next node (nextSibling()).
eType
NodeType An integer indicating which type of node this is.
@ TEXT
The node is a Text node.
@ ELEMENT
The node is an Element.
ConstIterT< XmlNode > const_iter
Type of a constant iterator over the entire array.
bool isNamed(const String &name) const
True if the element name is name.
XmlNode ownerElement() const
Returns the owning element of this attribute.
XmlNode expectedChild(const String &name) const
Child node of this node with name name.
XmlNode nextWithName(const String &name) const
Returns the next node after this node having the name name.
Integer valueAsInteger(bool throw_exception=false) const
Node value converted to integer.
XmlNode parent() const
Parent of this node (null if none).
iterator begin()
Returns an iterator over the first element of the array.
XmlNode nextSameType() const
Returns the next node of the same type.
void setAttrValue(const String &name, const String &value)
Sets the attribute name to the value value.
XmlNode childWithAttr(const String &elem_name, const String &attr_name, const String &attr_value) const
Returns the child of this node having the name elem_name and an attribute of name attr_name with valu...
String name() const
Node name.
bool valueAsBoolean(bool throw_exception=false) const
Node value converted to boolean.
XmlNode createNode(eType type, const String &name, const String &value)
Creates a node of a given type.
XmlNode prevWithName(const String &name) const
Returns the previous node before this node having the name name.
dom::Node domNode() const
void remove()
Removes this node from the document.
static const UShort ATTRIBUTE_NODE
The node is an Attr.
static const UShort ELEMENT_NODE
The node is an Element.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.