API to directly retrieve XML child content
This commit is contained in:
parent
a9d2a1c3f8
commit
beb0a96f42
@ -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 *);
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user