From d33a3b7d3587c22d54761e3ed04c85452d7ec550 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Fri, 30 May 2014 03:52:22 +0200 Subject: XmlNode::get_children, to get a list of matching children instead of the first --- src/xmpp/xmpp_stanza.cpp | 11 +++++++++++ src/xmpp/xmpp_stanza.hpp | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/xmpp') diff --git a/src/xmpp/xmpp_stanza.cpp b/src/xmpp/xmpp_stanza.cpp index c964c64..4290fc7 100644 --- a/src/xmpp/xmpp_stanza.cpp +++ b/src/xmpp/xmpp_stanza.cpp @@ -162,6 +162,17 @@ XmlNode* XmlNode::get_child(const std::string& name, const std::string& xmlns) c return nullptr; } +std::vector XmlNode::get_children(const std::string& name, const std::string& xmlns) const +{ + std::vector res; + for (auto& child: this->children) + { + if (child->name == name && child->get_tag("xmlns") == xmlns) + res.push_back(child); + } + return res; +} + XmlNode* XmlNode::add_child(XmlNode* child) { child->parent = this; diff --git a/src/xmpp/xmpp_stanza.hpp b/src/xmpp/xmpp_stanza.hpp index 53e0139..a34ef50 100644 --- a/src/xmpp/xmpp_stanza.hpp +++ b/src/xmpp/xmpp_stanza.hpp @@ -86,9 +86,13 @@ public: */ std::string get_tail() const; /** - * Get a pointer to the first child element with that name + * Get a pointer to the first child element with that name and that xml namespace */ XmlNode* get_child(const std::string& name, const std::string& xmlns) const; + /** + * Get a vector of all the children that have that name and that xml namespace. + */ + std::vector get_children(const std::string& name, const std::string& xmlns) const; /** * Add a node child to this node. Assign this node to the child’s parent. * Returns a pointer to the newly added child. -- cgit v1.2.3