Xport Interface: markup::empty
Reveals if the called markup object contains one or more children, or
is empty.
bool markup::empty();
Parameters
None
Returns
Returns true
if the called markup object is empty (contains no children), or false
otherwise.
Remarks
This operation is used to determine if a markup object contains markup children. The operation is only relevant when called on derived element
objects, since element
is the only type derived from markup
which can contain other markup objects. If called on a derived element
object, returns true
if the element contains no children (other markup objects), and false
if the element does contain
children.
This operation always returns false
when called from any markup derived type other than element
, which includes pcdata
,
comment
, and procinstr
.
Complexity
Constant
Example
#include "xhtml_doc.h"
#include "xport_brochure.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
markup::iterator it = doc.begin();
++it;
if (it->markup_type() == mt_element && it->tag() == html) {
it = doc.insert(it, procinstr("php include 'somefile.htm';"));
doc.insert(it, comment("This is a comment placed in the root of the document"));
}
*doc.body() << (element(p) << "Simple xhtml document.");
markup::const_descendant_iterator dit = doc.descendant_begin();
for (; dit != doc.descendant_end(); ++dit) {
switch (dit->markup_type())
{
case mt_element:
std::cout << "Element " << dit->tag_name();
break;
case mt_pcdata:
std::cout << "PCDATA";
break;
case mt_comment:
std::cout << "Comment";
break;
case mt_processing_instruction:
std::cout << "Processing Instruction";
break;
case mt_doctype_declaration:
std::cout << "Doctype declaration";
break;
default:
break;
}
std::cout << (dit->empty() ? " does not have " : " has ") << "children.\n";
}
std::cout << "\n\n\n";
formatter fmtr(std::cout);
doc.write(fmtr);
return 0;
}