瀏覽代碼

Added ChildElementCount()

Added the ChildElementCount function that was initially suggested by msteiger on sourceforge for the original tinyxml.  Modified to work with TinyXML-2.
kb1sph 3 年之前
父節點
當前提交
5926ec938a
共有 1 個文件被更改,包括 28 次插入0 次删除
  1. 28 0
      tinyxml2.cpp

+ 28 - 0
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.