From 5926ec938a962c7c8b6ea80d0e9debabf780e9f4 Mon Sep 17 00:00:00 2001 From: kb1sph Date: Mon, 6 Feb 2023 19:04:57 -0500 Subject: [PATCH 1/2] Added ChildElementCount() Added the ChildElementCount function that was initially suggested by msteiger on sourceforge for the original tinyxml. Modified to work with TinyXML-2. --- tinyxml2.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 4b561b3..4e95fb8 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -822,6 +822,34 @@ XMLNode::~XMLNode() } } +// ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2. + +int XMLNode::ChildElementCount(const char *value) const { + int count = 0; + + const XMLElement *e = FirstChildElement(value); + + while (e) { + e = e->NextSiblingElement(value); + count++; + } + + return count; +} + +int XMLNode::ChildElementCount() const { + int count = 0; + + const XMLElement *e = FirstChildElement(); + + while (e) { + e = e->NextSiblingElement(); + count++; + } + + return count; +} + const char* XMLNode::Value() const { // Edge case: XMLDocuments don't have a Value. Return null. From 904ad04bea0ee798d5e059410faf45de65a4eb0f Mon Sep 17 00:00:00 2001 From: kb1sph Date: Mon, 6 Feb 2023 19:07:13 -0500 Subject: [PATCH 2/2] Added ChildElementCount Added ChildElementCount suggested by msteiger on sourceforge for original tinyxml. Modified for TinyXML-2. --- tinyxml2.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tinyxml2.h b/tinyxml2.h index b0c8b6c..66ca3b2 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -732,6 +732,12 @@ public: return 0; } + // ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2. + + int ChildElementCount(const char *value) const; + + int ChildElementCount() const; + /** The meaning of 'value' changes for the specific type. @verbatim Document: empty (NULL is returned, not an empty string)