13
0

API to directly retrieve XML child content

This commit is contained in:
Robin Gareus 2022-01-13 00:03:00 +01:00
parent a9d2a1c3f8
commit beb0a96f42
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 22 additions and 0 deletions

View File

@ -130,6 +130,8 @@ public:
const std::string& set_content(const std::string&);
XMLNode* add_content(const std::string& s = std::string());
const std::string& child_content() const;
const XMLNodeList& children(const std::string& str = std::string()) const;
XMLNode* child(const char*) const;
XMLNode* add_child(const char *);

View File

@ -381,6 +381,26 @@ XMLNode::set_content(const string& c)
return _content;
}
/* Return the content of the first content child
*
* `<node>Foo</node>`.
* the `node` is not a content node, but has a child-node `text`.
*
* This method effectively is identical to
* return this->child("text")->content()
*/
const string&
XMLNode::child_content() const
{
static const string empty = "";
for (XMLNodeList::const_iterator n = children ().begin (); n != children ().end (); ++n) {
if ((*n)->is_content ()) {
return (*n)->content ();
}
}
return empty;
}
XMLNode*
XMLNode::child (const char* name) const
{