Skip to content

Commit

Permalink
Merge pull request #933 from kb1sph/master
Browse files Browse the repository at this point in the history
Added ChildElementCount()
  • Loading branch information
leethomason authored Nov 21, 2023
2 parents 5203571 + 904ad04 commit ac23537
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tinyxml2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions tinyxml2.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,12 @@ class TINYXML2_LIB XMLNode
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)
Expand Down

0 comments on commit ac23537

Please sign in to comment.