Xport Interface: markup::markup_type
Returns the appropriate xhtml_markup_type
enumeration for the called markup object.
xhtml_markup_type markup::markup_type() const;
Parameters
None
Returns
Returns an enumerator of xhtml_markup_type
. Can be one of the following values: mt_element
, mt_pcdata
, mt_comment
,
mt_processing_instruction
, mt_doctype_declaration
, or mt_unknown
.
Remarks
This operation is used to determine the derived type of an object. This operation is overridden from all types derived from markup
to
return the respective enumerator for that type. By default, markup
returns mt_unknown
for this operation. Actually, mt_unknown
should never be returned, as it is impossible to create an object of the base type markup
.
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;
}