85 operator bool() const noexcept {
return node !=
nullptr; }
87 bool operator!() const noexcept {
return node ==
nullptr; }
89 bool operator==(
const Node &other)
const noexcept {
return node == other.node; }
91 bool operator!=(
const Node &other)
const noexcept {
return !(*
this == other); }
224 try { queryAttribute(name, attr); }
225 catch (...) {
return T(0); }
228 queryAttribute(name, attr);
267 template<
typename T> T
GetValue(
bool silent =
true)
const
272 try { queryValue(val); }
273 catch (...) {
return T(0); }
289 void queryValue(
int &value)
const;
291 void queryValue(
unsigned int &value)
const;
293 void queryValue(
bool &value)
const;
295 void queryValue(
double &value)
const;
297 void queryValue(
float &value)
const;
300 SCharsetConverter conv;
317 void queryAttribute(
const StringUTF8 &name,
int &value)
const;
319 void queryAttribute(
const StringUTF8 &name,
unsigned int &value)
const;
321 void queryAttribute(
const StringUTF8 &name,
bool &value)
const;
323 void queryAttribute(
const StringUTF8 &name,
double &value)
const;
325 void queryAttribute(
const StringUTF8 &name,
float &value)
const;
327 void count_subnondes();
330 size_t nb_subnodes, nb_subelems;
348 try { queryAttribute(name, attr); }
352 queryAttribute(name, attr);
435 Document(
const Path &fname,
bool char_conversion_throws =
true);
437 Document(
const char *content,
bool char_conversion_throws =
true);
446 operator bool() const noexcept {
return doc !=
nullptr; }
448 bool operator!() const noexcept {
return doc ==
nullptr; }
500 std::unique_ptr<tinyxml2::XMLDocument> doc;
502 SCharsetConverter conv;
Attribute & operator++()
Move to next attribute.
void Save()
Saves to file.
bool IsText()
Checks if the node is a text.
virtual StringUTF8 GetValue() const override
Gets the content of the node.
Comment PushFrontComment(const StringUTF8 &text)
Adds a comment at the front of the children list.
Node PushBackClone(Node &n, bool recursive=false)
Adds a copy of a node at the end of the children list.
size_t GetNbSubelements() const
Returns the number of sub-elements.
void Clear()
Removes all children.
Text(const Text &)=default
Text & operator=(const Text &)=default
Comment PushBackComment(const StringUTF8 &text)
Adds a comment at the end of the children list.
void SetName(const StringUTF8 &s)
Sets the label of the element.
bool operator!() const noexcept
Checks if the document is not open.
StringUTF8 GetName() const
Gets the label of the element.
bool IsComment()
Checks if the node is a comment.
Element EndElement()
Gets a null node.
Node EndNode()
Gets a null node.
Element(const Element &)=default
Text AsText()
Converts to text.
Element GetRoot()
Gets the first element.
Element & operator=(const Element &)=default
Element PushBackElement(const StringUTF8 &name)
Adds an element at the end of the children list.
Element AsElement()
Converts to element.
Attribute EndAttribute()
Gets the null attribute.
Element InsertElement(Node &n, const StringUTF8 &name)
Inserts an element after a node.
Element GetLastElement(const StringUTF8 &name="")
Gets the last child element.
Element GetNextSiblingElement(const StringUTF8 &name="")
Gets the next sibling element.
Element BeginElement()
Gets the first child element.
bool operator!() const noexcept
Checks if the node is null.
Attribute & operator=(const Attribute &)=default
Text PushBackText(const StringUTF8 &text, bool cdata=false)
Adds a text at the end of the children list.
Element GetLastChildElement(const StringUTF8 &name="")
Gets the last child element.
Text PushFrontText(const StringUTF8 &text, bool cdata=false)
Adds a text at the front of the children list.
Node GetLastNode()
Gets the last child node.
size_t GetNbSubnodes() const
Returns the number of sub-nodes.
Node GetParent()
Gets the parent node if any.
Comment InsertComment(Node &n, const StringUTF8 &text)
Inserts a comment after a node.
virtual ~Element() override
Destructor.
const StringUTF8 & GetEncoding() const noexcept
Gets the character encoding of the file.
const StringUTF8 & GetVersion() const noexcept
Gets the XML version of the file.
Document & operator=(const Document &)=delete
Element GetFirstChildElement(const StringUTF8 &name="")
Gets the first child element.
Node GetLastChild()
Gets the last child node.
A convenience class for file paths.
bool IsElement()
Checks if the node is an element.
virtual StringUTF8 GetValue() const
Gets the content of the node.
Element GetPreviousSiblingElement(const StringUTF8 &name="")
Gets the previous sibling element.
Node GetFirstNode()
Gets the first child node.
void SetValue(const StringUTF8 &s)
Sets the content of the node.
Element BeginElement()
Gets the first child element.
Document(const StringUTF8 &encoding="UTF-8", const StringUTF8 &version="1.0", bool char_conversion_throws=true)
Constructor.
void SetAttribute(const StringUTF8 &name, const StringUTF8 &value)
Sets the value of an attribute.
StringUTF8 AsString()
Exports the document to a string.
Element & operator++()
Moves to the next sibling element.
void SetValue(const StringUTF8 &value)
Sets the value of the attribute.
StringUTF8 GetName() const
Gets the name of the attribute.
T GetAttribute(const StringUTF8 &name, bool silent=true) const
Gets an attribute.
Node EndNode()
Gets a null node.
Node GetFirstChild()
Gets the first child node.
Element GetFirstElement(const StringUTF8 &name="")
Gets the first child element.
bool operator!=(const Attribute &other) const noexcept
Comparison operator.
Comment PushBackComment(const StringUTF8 &text)
Adds a comment at the end of the children list.
Node BeginNode()
Gets the first child node.
Attribute Next()
Gets next attribute.
Text InsertText(Node &n, const StringUTF8 &text, bool cdata=false)
Inserts a text after a node.
virtual ~Node()
Destructor.
Node & operator++()
Moves to the next sibling node.
Node GetPreviousSibling()
Gets the previous sibling node.
virtual ~Text() override
Destructor.
Node GetNextSibling()
Gets the next sibling node.
Attribute BeginAttribute()
Gets the first attribute.
StringUTF8 GetFirstChildText()
Gets the first child as text.
Element InsertElement(Node &n, const StringUTF8 &name)
Inserts an element after a node.
Node & operator=(const Node &)=default
Element PushFrontElement(const StringUTF8 &name)
Adds an element at the front of the children list.
Comment AsComment()
Converts to comment.
A character string class.
Node PushBackClone(Node &n, bool recursive=false)
Adds a copy of a node at the end of the children list.
Node(const Node &)=default
bool IsCData() const
Is the text a CData?
const Path & GetFilename() const noexcept
Gets the filename if the document exists on the disk.
virtual ~Document()
Destructor.
bool operator==(const Attribute &other) const noexcept
Comparison operator.
Element PushBackElement(const StringUTF8 &name)
Adds an element at the end of the children list.
void RemoveChild(Node &n)
Removes a child node.
Comment InsertComment(Node &n, const StringUTF8 &text)
Inserts a comment after a node.
bool operator!=(const Node &other) const noexcept
Comparison operator.
T GetValue(bool silent=true) const
Gets the value of the attribute.
Element EndElement()
Gets a null node.
Node BeginNode()
Gets the first child node.
Attribute(const Attribute &)=default
bool operator==(const Node &other) const noexcept
Comparison operator.
void RemoveAttribute(const StringUTF8 &name)
Removes an attribute.