26#include <libxml/parser.h>
27#include <libxml/tree.h>
28#include <libxml/xmlwriter.h>
44 operator bool()
const {
return node !=
nullptr; }
46 std::string_view
name()
const {
return (
const char *)
node->name; }
55 std::string
getProperty(
const char *
name,
const std::string &def)
const;
71 while (
mNode &&
mNode->type != XML_ELEMENT_NODE)
80 }
while (
mNode &&
mNode->type != XML_ELEMENT_NODE);
107 if (
node->children &&
node->children->type == XML_TEXT_NODE)
108 return (
const char *)
node->children->content;
114 if (
node->type != XML_ELEMENT_NODE)
117 for (xmlAttrPtr prop =
node->properties; prop; prop = prop->next) {
118 if (xmlStrEqual(prop->name, BAD_CAST
name)) {
120 return reinterpret_cast<const char*
>(prop->children->content);
179 if (child.name() ==
name)
196 Document(
const std::string &filename,
bool useResman =
true);
215 return mDoc ? xmlDocGetRootElement(
mDoc) :
nullptr;
231 Writer(
const std::string &fileName);
239 void addAttribute(
const char *name,
const std::string &value);
246 template<
typename Enum, std::enable_if_t<std::is_enum_v<Enum>,
bool> = true>
255 template<
typename Enum, std::enable_if_t<std::is_enum_v<Enum>,
bool>>
263 xmlTextWriterStartElement(
mWriter, BAD_CAST name);
268 xmlTextWriterEndElement(
mWriter);
278 xmlTextWriterWriteAttribute(
mWriter, BAD_CAST name, BAD_CAST value);
283 xmlTextWriterWriteAttribute(
mWriter, BAD_CAST name, BAD_CAST
toString(value).c_str());
288 xmlTextWriterWriteAttribute(
mWriter, BAD_CAST name, BAD_CAST
toString(value).c_str());
293 xmlTextWriterWriteAttribute(
mWriter, BAD_CAST name, BAD_CAST
toString(value).c_str());
298 xmlTextWriterWriteAttribute(
mWriter, BAD_CAST name, BAD_CAST (value ?
"1" :
"0"));
303 xmlTextWriterWriteString(
mWriter, BAD_CAST text.c_str());
A helper class for parsing an XML document, which also cleans it up again (RAII).
Node rootNode() const
Returns the root node of the document (or NULL if there was a load error).
Iterator(xmlNodePtr node)
bool operator!=(const Iterator &other) const
Helper class to iterate over the children of a node.
Children(xmlNodePtr node)
std::string_view name() const
int getProperty(const char *name, int def) const
double getFloatProperty(const char *name, double def) const
Node(xmlNodePtr node=nullptr)
Node findFirstChildByName(const char *name) const
Children children() const
std::string_view textContent() const
bool hasAttribute(const char *name) const
bool attribute(const char *name, T &value) const
bool getBoolProperty(const char *name, bool def) const
Helper class for writing out XML data.
void writeText(const std::string &text)
void startElement(const char *name)
void addAttribute(const char *name, const std::string &value)
void init()
Initializes the XML engine.
bool getBoolFromString(std::string text, bool def)
Returns a bool value depending on the given string value.
std::string toString(const T &arg)
Converts the given value to a string using std::stringstream.
void fromString(const char *str, FillMode &value)