diff options
Diffstat (limited to 'src/utils/xml.h')
-rw-r--r-- | src/utils/xml.h | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/utils/xml.h b/src/utils/xml.h index 787504bb..fe896c60 100644 --- a/src/utils/xml.h +++ b/src/utils/xml.h @@ -47,7 +47,7 @@ namespace XML std::string_view textContent() const; template<typename T> - bool attribute(const char *name, T &value); + bool attribute(const char *name, T &value) const; bool hasAttribute(const char *name) const; int getProperty(const char *name, int def) const; @@ -66,10 +66,19 @@ namespace XML class Iterator { public: - explicit Iterator(xmlNodePtr node) : mNode(node) {} + explicit Iterator(xmlNodePtr node) : mNode(node) + { + while (mNode && mNode->type != XML_ELEMENT_NODE) + mNode = mNode->next; + } bool operator!=(const Iterator &other) const { return mNode != other.mNode; } - void operator++() { mNode = mNode->next; } + void operator++() + { + do { + mNode = mNode->next; + } while (mNode && mNode->type != XML_ELEMENT_NODE); + } Node operator*() const { return mNode; } private: @@ -117,7 +126,7 @@ namespace XML } template<typename T> - inline bool Node::attribute(const char *name, T &value) + inline bool Node::attribute(const char *name, T &value) const { if (const char *str = attribute(name)) { @@ -195,13 +204,13 @@ namespace XML * Returns the root node of the document (or NULL if there was a * load error). */ - Node rootNode(); + Node rootNode() const; private: xmlDocPtr mDoc; }; - inline Node Document::rootNode() + inline Node Document::rootNode() const { return mDoc ? xmlDocGetRootElement(mDoc) : nullptr; } |