When called on a derived element object, clears all children from the object.
void markup::clear();
Parameters
None
Returns
Nothing.
Remarks
When called on a derived element object, this operation clears all child markup objects from the element. When called on the other
types derived from markup, (
pcdata, comment, and procinstr), this operation does nothing, since these types can contain no children.
Although this operation is relevant only to element derived objects, the clear() operation is implemented in markup,
since it is markup which manages any child markup objects.
Complexity
Linear
Example
#include "xhtml_doc.h"
#include "xport_brochure.h"
#include <algorithm>
#include <iostream>
// function object used in std::find_if()
struct has_id
{
public:
has_id(const std::string& find_id) : id_val(find_id) {}
bool operator()(const Xport::markup& mkup) { return mkup.attribute(Xport::id) == id_val; }
private:
std::string id_val;
};
// unary predicate to count descendant elements
bool count_all(const Xport::markup& mkup) { return true; }
int main(int argc, char* argv[])
{
using namespace Xport;
// create an xhtml strict root document and stylesheet
document doc(root_doc);
stylesheet ss;
// populate them with Xport Brochure
xport_brochure broch;
broch.create(doc, ss);
// use std::find_if() to find element with id = 'content'
markup::descendant_iterator dit = std::find_if(doc.descendant_begin(), doc.descendant_end(), has_id("content"));
if (dit != doc.descendant_end()) {
// found main div element. Count it's descendants
markup::size_type markup_count = std::count_if(dit->descendant_begin(), dit->descendant_end(), count_all);
std::cout << "Xport Brochure's contains " << markup_count << " markup objects.\n\n";
std::cout << "Calling clear() on main div element.\n\n";
dit->clear();
// now count descendants again
markup_count = std::count_if(dit->descendant_begin(), dit->descendant_end(), count_all);
std::cout << "Main div element is " << (markup_count == 0 ? "now" : "not") << " empty.\n\n";
}
return 0;
}
Datasoft Solutions is proud to present their landmark product, Work Time Studio. Utilizing the tree container library, Work Time Studio provides
unparalleled features in personal time, project and task management
software. If you're looking for a way to increase your productivity,
visit Work Time Studio's product website, and start being more productive
today.