Xport Interface: element::markup_type
Returns the mt_element
enumerator of xhtml_markup_type
, to indicate the called markup object is an element
.
xhtml_markup_type element::markup_type() const;
Parameters
None
Returns
Returns mt_element, which is an enumerator of xhtml_markup_type
.
Remarks
This operation is used to determine the derived type of the called object derived from markup
. This operation is overridden from all
types derived from markup
to return the respective enumerator for that type. This operation is overridden in element
to
simply return the enumerator mt_element
.
Many object oriented experts feel that operations such as this, break the object oriented paradigm, and that there should be no reason to disclose the
derived type of an object. In practice, however, this need often arises, so this operation is included for those events.
Complexity
Constant
Example
#include "xhtml_doc.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
*doc.body() << comment("Sample xhtml document to test the markup_type() operation");
*doc.body() << procinstr("php include 'somedoc.htm'");
markup::iterator it = doc.body()->insert(element(ul));
*it << (element(li) << "List item 1");
*it << (element(li) << "List item 2");
*it << (element(li) << "List item 3");
formatter fmtr(std::cout);
doc.write(fmtr);
std::cout << "\n\n";
markup::const_descendant_iterator dit = doc.descendant_begin();
for (; dit != doc.descendant_end(); ++dit) {
switch (dit->markup_type())
{
case mt_doctype_declaration:
std::cout << "Doctype declaration.\n";
break;
case mt_element:
std::cout << dit->tag_name() << " element.\n";
break;
case mt_pcdata:
std::cout << "PCDATA.\n";
break;
case mt_comment:
std::cout << "Comment.\n";
break;
case mt_processing_instruction:
std::cout << "Processing instruction.\n";
break;
default:
break;
}
}
return 0;
}