Xport Interface: markup::tag_name
When called on a derived element
object, returns the tag name of the called element
.
std::string markup::tag_name();
Parameters
None
Returns
When called from a derived element
, returns a string which specifies the tag name of the called element.
Remarks
This operation is used to retrieve the tag name of the called derived element
object. When called on any other type derived from markup
other than element
, an empty string is returned.
Complexity
Constant
Example
#include "xhtml_doc.h"
#include <iostream>
void print_element(const Xport::markup& mkup, int depth);
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
*doc.body() << (element(h1) << "Test document");
*doc.body() << (element(p) << "This is a test document generated by Xport.");
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");
print_element(*doc.html(), 0);
return 0;
}
void print_element(const Xport::markup& mkup, int depth)
{
using namespace Xport;
std::cout << std::string(depth, ' ') << mkup.tag_name() << "\n";
markup::const_iterator it = mkup.begin();
for (; it != mkup.end(); ++it) {
if (it->markup_type() == mt_element) {
print_element(*it, depth + 1);
}
}
}